#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m, ans = 0, x = 0, y = 0;
  cin >> n >> m;
  if (n > m)
    cout << n - m << "\n";
  else {
    while (n < m) {
      if (m % 2)
        m++;
      else
        m /= 2;
      ans++;
    }
    ans += (n - m);
    cout << ans << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
