#include <bits/stdc++.h>
using namespace std;
long long n, m;
void in() { cin >> n >> m; }
void out() {
  int s = 0;
  if (n > m) {
    cout << n - m;
    return;
  }
  while (n < m) {
    s++;
    n <<= 1;
  }
  int diff = n - m;
  n >>= 1;
  long long x = 2;
  long long c = 0;
  while (x <= diff && c < s) {
    c++;
    x *= 2;
  }
  x /= 2;
  while (diff > 0) {
    diff -= x;
    s++;
    while (diff < x) {
      x /= 2;
    }
  }
  cout << s;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    in();
    out();
  }
  return 0;
}
