#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  if (n > m) {
    ans = n - m;
  } else {
    while (n != m) {
      if (m % 2 == 0 && m > n) {
        ans++;
        m /= 2;
      } else {
        if (n >= m) {
          ans += n - m;
          break;
        }
        m = (m + 1) / 2;
        ans += 2;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
