#include <bits/stdc++.h>
using namespace std;
map<int, int> mm;
int mv[100000] = {0};
int bfs(int n, int m) {
  queue<int> mq;
  mq.push(n);
  mv[n] = 0;
  while (!mq.empty()) {
    int r = mq.front();
    if (r == m) return mv[r];
    mq.pop();
    int x, y;
    x = r - 1;
    y = r * 2;
    if (x > 0 && x < 10001 && mv[x] == 0) {
      mv[x] = mv[r] + 1;
      mq.push(x);
    }
    if (y > 0 && y < 10001 && mv[y] == 0) {
      mv[y] = mv[r] + 1;
      mq.push(y);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int k = bfs(n, m);
  cout << k << endl;
  return 0;
}
