#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int cs[20001];
int n, m;
int main() {
  cin >> n >> m;
  q.push(n);
  cs[n] = 1;
  while (!cs[m]) {
    int s = q.front();
    q.pop();
    if (s > 0) {
      if (s < m)
        if (!cs[2 * s]) {
          cs[2 * s] = cs[s] + 1;
          q.push(2 * s);
        }
      if (!cs[s - 1]) {
        cs[s - 1] = cs[s] + 1;
        q.push(s - 1);
      }
    }
  }
  cout << cs[m] - 1 << endl;
  return 0;
}
