import std.stdio;
import std.string;
import std.conv;

void main() {
    
    // input
    int n = to!int(readln.chomp);
    int k = to!int(readln.chomp);
    
    int[] x, y;
    x.length = y.length = k;
    
    for(int i=0; i<k; ++i) {
        auto temp = readln.split;
        x[i] = to!int(temp[0]);
        y[i] = to!int(temp[1]);
    }
    
    // output
    for(int i=0; i<k; ++i) {
        if(x[i] > n / 2)    x[i] = n - x[i] + 1;
        if(y[i] > n / 2)    y[i] = n - y[i] + 1;
        
        int min = x[i] < y[i] ? x[i] : y[i];
        writeln((min + 2) % 3 + 1);
    }
    
}