#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int ans[100005] = {0};
int main() {
  ios::sync_with_stdio(false);
  int n, m, x;
  cin >> n >> m;
  ans[n]++;
  q.push(n);
  while (!ans[m]) {
    x = q.front();
    q.pop();
    if ((x - 1) > 0 && !ans[x - 1]) {
      ans[x - 1] = ans[x] + 1;
      q.push(x - 1);
    }
    if (2 * x < max(2 * m, 2 * n) && !ans[2 * x]) {
      ans[2 * x] = ans[x] + 1;
      q.push(2 * x);
    }
  }
  cout << (ans[m] - 1);
  return 0;
}
