#include <bits/stdc++.h>
using namespace std;
int vis[100000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, ans = 0;
  cin >> n >> m;
  queue<pair<int, int>> q;
  q.push({n, 0});
  while (!q.empty()) {
    int x = q.front().first, cnt = q.front().second;
    q.pop();
    if (x > 10000 || x < 0 || vis[x]) continue;
    vis[x] = 1;
    if (x == m) {
      cout << cnt << '\n';
      return 0;
    }
    q.push({x * 2, cnt + 1});
    q.push({x - 1, cnt + 1});
  }
  return 0;
}
