#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
using namespace std;
#define maxn 100010
#define ll long long
#define mm(a,b) memset(a,b,sizeof(a))
int n,q;
int gcd(int a,int b){
return b==0?a:gcd(b,a%b);
}
int main()
{
int x,y;
scanf("%d%d",&n,&q);
while(q--)
{
scanf("%d%d",&x,&y);
if(gcd(x,y)==1) printf("1\n");
else printf("2\n");
}
}