N,M=map(int,input().split()) MAP=[[-1]*N for i in range(N)] MAP[0][0]=1 MAP[N-1][N-1]=1 Q=[(0,0)] c=0 while Q: x,y=Q.pop() if c==2998: break for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]: if 0<=z