#include <bits/stdc++.h>
using namespace std;

int main() {
	int a, b; cin >> a >> b;
	int ret = 4;
	if (a+b >= 15 && b >= 8) ret = 1;
	else if (a+b >= 10 && b >= 3) ret = 2;
	else if (a+b >= 3) ret = 3;
	cout << ret << '\n';
    return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <cstring>
#include <functional>
#include <map>
#define LL long long
#define lson(rt) (rt << 1)
#define rson(rt) (rt << 1 | 1)
using namespace std;

const int N = 1e6 + 10;
map<LL, LL> memo;
LL x, y;

LL fun (LL y)
{
    if(x >= y) return abs(x - y);
    if(memo.find(y) != memo.end()) return memo[y];
    if(y & 1) {
        return memo[y] = min(abs(x - y), min(fun(y + 1) + 1, fun(y - 1) + 1));
    } else {
        return memo[y] = min(abs(x - y), fun(y / 2) + 1LL);
    }
}

void solve()
{
    cin >> x >> y;
    cout << fun(y) << endl;
}

int main ()
{
   // ios::sync_with_stdio(false);
   // cin.tie(0); cout.tie(0);

    solve();

    return 0;
}
