#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  bool explored[20000] = {};
  int distance[20000];
  for (int i = 0; i < 20000; i++) distance[i] = -1;
  queue<int> q;
  cin >> n >> m;
  q.push(n);
  distance[n] = 0;
  while (true) {
    int x = q.front();
    if (x == m) {
      cout << distance[x] << endl;
      return 0;
    }
    q.pop();
    if (!explored[x]) {
      if (!explored[x - 1] && x - 1 >= 1 && x - 1 <= 20000) {
        q.push(x - 1);
        if (distance[x - 1] == -1) distance[x - 1] = distance[x] + 1;
      }
      if (!explored[x * 2] && x * 2 >= 1 && x * 2 <= 20000) {
        q.push(x * 2);
        if (distance[x * 2] == -1) distance[x * 2] = distance[x] + 1;
      }
      explored[x] = true;
    }
  }
  return 0;
}
