fun main(args:Array<String>):Unit {
    val n = readLine()!!.trim().toInt()
    val k = readLine()!!.trim().toInt()
    repeat(k){
        val (x, y) = readLine()!!.trim().split(' ').map(String::toInt)
        val diff = listOf(n - x + 1, n - y + 1, x, y).min()!! + 2
        println(diff % 3 + 1)
    }
}

