#include <bits/stdc++.h>
using namespace std;
long long n, m, dp[100005];
int main() {
  for (int i = 0; i < 100005; i++) dp[i] = 1e9;
  cin >> n >> m;
  queue<int> q;
  q.push(n);
  dp[n] = 0;
  bool p = 0;
  while (!q.empty()) {
    int y = q.front();
    q.pop();
    if (dp[y * 2] >= dp[y] + 1) {
      if (y * 2 <= m || (y * 2 >= m && y <= m)) {
        q.push(y * 2);
        dp[y * 2] = dp[y] + 1;
        if (y * 2 >= m) p = 1;
      }
    }
    if (dp[y - 1] >= dp[y] + 1 && (y - 1) > 0) {
      q.push(y - 1);
      dp[y - 1] = dp[y] + 1;
    }
  }
  cout << dp[m];
  return 0;
}
