#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<cstring>
using namespace std;
const int maxn=1e5+100;
const int inf=0x3f3f3f3f;
int a[maxn];
int main(){
int n,q;
scanf("%d %d",&n,&q);
while(q--){
int x,y;
scanf("%d %d",&x,&y);
if(__gcd(x,y)==1) printf("1\n");
else printf("2\n");
}
}