#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  const int INF = 1e9;
  vector<int> dist(400000, INF);
  dist[n] = 0;
  queue<int> q;
  q.push(n);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    if (x == m) break;
    if (x - 1 >= 0 && dist[x - 1] == INF) {
      dist[x - 1] = dist[x] + 1;
      q.push(x - 1);
    }
    if (dist[2 * x] == INF && x * 2 <= 40000) {
      dist[2 * x] = dist[x] + 1;
      q.push(2 * x);
    }
  }
  cout << dist[m];
  return 0;
}
