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