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