#include <bits/stdc++.h>
using namespace std;
int n, m, OO = 1e8;
int dp[100001];
int solve(int x) {
  if (x <= 0 || x > 1e5) return OO;
  if (x == m) return 0;
  int &ret = dp[x];
  if (ret != -1) return ret;
  ret = OO;
  if (x > m)
    ret = min(ret, 1 + solve(x - 1));
  else {
    ret = min(ret, 1 + solve(x * 2));
    ret = min(ret, 1 + solve(x - 1));
  }
  return ret;
}
int main() {
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  cout << solve(n) << endl;
  return 0;
}
