#include #define rep(i, a, n) for(int i = a; i < n; i++) #define REP(i, n) rep(i, 0, n) #define repb(i, a, b) for(int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define int long long #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; typedef pair P; typedef pair PP; const int mod = 1000000007; const int INF = 1e12; int d[1010][1010]; signed main(){ ios::sync_with_stdio(false); cin.tie(0); int x, y; cin >> x >> y; x += 500; y += 500; rep(i, 0, 1010) rep(j, 0, 1010) d[i][j] = INF; d[x][y] = 0; priority_queue, greater > q; q.push(PP(0, P(x, y))); while(!q.empty()){ PP p = q.top(); q.pop(); int nowd = p.first; int nowx = p.second.first; int nowy = p.second.second; int nextx = nowy + nowx - 500; int nexty = nowx - nowy + 500; // cout << nowd << " " << nowx << " " << nowy << " " << nextx << " " << nexty << endl; if(d[nowy][nowx] > nowd + 1){ d[nowy][nowx] = nowd + 1; q.push(PP(nowd + 1, P(nowy, nowx))); } if(nexty < 0 || nexty > 1000 || nextx < 0 || nextx > 1000) continue; if(d[nextx][nexty] > nowd + 1){ d[nextx][nexty] = nowd + 1; q.push(PP(nowd + 1, P(nextx, nexty))); } if(nexty == nextx) break; } int ans = INF; rep(i, 0, 1010) chmin(ans, d[i][i]); if(ans == INF) ans = -1; cout << ans << endl; }