#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string.h>
using namespace std;
typedef long long LL;
int gcd(int x,int y)
{
if(y==0)
{
return x;
}
else
{
return gcd(y,x%y);
}
}
int main()
{
int n,q;
scanf("%d%d",&n,&q);
while(q--)
{
int x,y;
scanf("%d%d",&x,&y);
if(gcd(x,y)>=2)
{
printf("2\n");
}
else
{
printf("1\n");
}
}
return 0;
}