#include<cstdio>
#include<set>
#include<vector>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
int gcd(int x,int y){
if(y==0)return x;
return gcd(y,x%y);
}
int main(){
int n,q;
while(~scanf("%d%d",&n,&q)){
int a,b;
while(q--){
scanf("%d%d",&a,&b);
if(gcd(a,b)==1)
printf("1\n");
else
printf("2\n");
}
}
}