n = gets.to_i
k = gets.to_i
color = [3, 1, 2]
arr = []
k.times{
    a, b = gets.chomp.split.map(&:to_i)
    x = a
    x = (n + 1 - a) if a > (n + 1) / 2
    y = b
    y = (n + 1 - b) if b > (n + 1) / 2
    puts color[[x, y].min % 3]
}
