#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int man = 0, ans = 0, n, m;
  int a[1000];
  while (cin >> n >> m) {
    ans = 0;
    if (n > m) {
      printf("%d\n", n - m);
    } else {
      while (n < m) {
        if (m % 2 != 0) {
          m++;
          ans++;
        }
        m /= 2;
        ans++;
      }
      ans += n - m;
      printf("%d\n", ans);
    }
  }
}
