#include <bits/stdc++.h>
using namespace std;
queue<int> q;
bool visit[100009] = {false};
int d = 0, u, v;
int bfs(int n, int m) {
  q.push(n);
  visit[n] = true;
  q.push(d);
  while (!q.empty()) {
    u = q.front();
    q.pop();
    d = q.front();
    q.pop();
    if (u == m) return d;
    if (u < m && !visit[2 * u]) {
      v = 2 * u;
      visit[v] = true;
      q.push(v);
      q.push(d + 1);
    }
    if (!visit[u - 1] && u > 1) {
      v = u - 1;
      visit[v] = true;
      q.push(v);
      q.push(d + 1);
    }
  }
}
int main() {
  int n, m, ans;
  cin >> n >> m;
  if (n >= m) {
    ans = n - m;
    cout << ans << endl;
    return 0;
  } else {
    ans = bfs(n, m);
    cout << ans << endl;
    return 0;
  }
}
