#include<bits/stdc++.h>
using namespace std;
int m,n,step;
int a[105][105];
int vis[105][105];
int h[13][2]={0,0,-2,-1,-2,-2,-1,-2,1,-2,2,-2,2,-1,2,1,2,2,1,2,-1,2,-2,2,-2,1};
struct node{
int x,y;
}s;
void bfs(int x,int y){
queue<node> q;
s.x=x,s.y=y;
q.push(s);
while(!q.empty()){
s=q.front();
q.pop();
x=s.x,y=s.y;
for(int i=1;i<=12;i++){
int hx=x+h[i][0];
int hy=y+h[i][1];
if(hx>=1&&hx<=100&&hy>=1&&hy<=100&&!vis[hx][hy]){
s.x=hx,s.y=hy;
q.push(s);
a[hx][hy]=a[x][y]+1;
vis[hx][hy]=1;
if(hx1&&hy1){
step=a[hx][hy];
return;
}
}
}
}
}
int main(){
while(cin>>m>>n&&(m!=1||n!=1)){
step=0;
memset(vis,0,sizeof(vis));
memset(a,0,sizeof(a));
bfs(m,n);
cout<<step<<endl;
}
return 0;
}