#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define INF_LL (ll)1e18 #define INF (int)1e9 #define REP(i, n) for(int i = 0;i < (n);i++) #define FOR(i, a, b) for(int i = (a);i < (b);i++) #define all(x) x.begin(),x.end() using ll = long long; using PII = pair; const double eps = 1e-10; templateinline void chmin(A &a, B b){if(a > b) a = b;} templateinline void chmax(A &a, B b){if(a < b) a = b;} map cnt; int main(void){ int x, y; cin >> x >> y; cnt[PII(x, y)] = -1; queue q; q.push({x, y}); while(q.size()){ x = q.front().first; y = q.front().second; q.pop(); if(x == y){ cout << (cnt[PII(x, y)] == -1 ? 0 : cnt[PII(x, y)]) << endl; return 0; } int now = cnt[PII(x, y)]; if(now == -1) now = 0; if(cnt[PII(y, x)] == 0){ cnt[PII(y, x)] = now+1; q.push({y, x}); } if(abs(x+y) < 10000 && abs(x-y) < 10000 && cnt[PII(x+y, x-y)] == 0){ cnt[PII(x+y, x-y)] = now+1; q.push({x+y, x-y}); } } cout << -1 << endl; }