#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define llong long long int main() { int x, y; cin >> x >> y; if((x+y) % 2 != 0 && x != 0 && y != 0) { cout << "-1\n"; return 0; } else if(x == y) { cout << "0\n"; return 0; } int times = 0; deque> cands; cands.push_back(make_pair(x, y)); while(true) { times++; int limit = cands.size(); rep(i, limit) { pair cand = cands.front(); cands.pop_front(); if(cand.first+cand.second == cand.first-cand.second) { cout << times << "\n"; return 0; } cands.push_back(make_pair(cand.second, cand.first)); cands.push_back(make_pair(cand.first+cand.second, cand.first-cand.second)); } } }