#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxn = 1e5 + 50;
int gcd(int x, int y)
{
if(y == 0)return x;
if(x < y)swap(x, y);
int t = x % y;
x = y;
y = t;
return gcd(x, y);
}
int main()
{
int n, q;
scanf("%d %d", &n, &q);
while(q--)
{
int a, b;
scanf("%d %d", &a, &b);
if(gcd(a, b) == 1)printf("1\n");
else printf("2\n");
}
return 0;
}