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