#include using namespace std; #define xx first #define yy second #define long long long typedef pair ii; map cnt; long process(int a, int b) { // if (b == 0 or a == 0) return 0; if (a == 1 and b == 1) return 0; if (cnt.count(ii(a, b))) return cnt[ii(a, b)]; if (a == 1) cnt[ii(a, b)] = process(a, b / 2) + process(a, b - b / 2) + 1; else if (b == 1) cnt[ii(a, b)] = process(a / 2, b) + process(a - a / 2, b) + 1; else cnt[ii(a, b)] = (1 + min( process(a, b - b / 2) + process(a, b / 2), process(a - a / 2, b) + process(a / 2, b) )); return cnt[ii(a, b)]; } int main() { int a, b; cin >> a >> b; cout << process(a, b); return 0; }