#include <bits/stdc++.h>
int main() {
  long int n, m, ans = 0;
  scanf("%ld%ld", &n, &m);
  if (n >= m) {
    printf("%ld\n", n - m);
  } else {
    while (n < m) {
      if (m % 2) {
        ++m;
        ++ans;
      } else {
        m = m / 2;
        ++ans;
      }
    }
    printf("%ld\n", ans + n - m);
  }
  return 0;
}
