Result: Accepted
Time: 72ms
Memory: 1712kB
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <string>
#include <ctype.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int maxen=100010;
int gcd(int x,int y){
return x==0?y:gcd(y%x,x);
}
void exchange(int x,int y){
int t=x;
x=y;
y=t;
}
int main(){
int n,q;
scanf("%d %d",&n,&q);
while(q--){
int s,t;
scanf("%d %d",&s,&t);
if(s>t){
exchange(s,t);
}
if(s==t+1||s==t-1){
printf("1\n");
}
else{
printf("2\n");
}
}
return 0;
}