#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m;
  int count;
  int sum;
  while (scanf("%d%d", &n, &m) != EOF) {
    count = 0;
    sum = 0;
    if (n == m) {
      printf("0");
      printf("\n");
      continue;
    }
    while (n < m) {
      n = n * 2;
      count++;
    }
    int k = n - m;
    sum += count;
    while (count != -1 && k != 0) {
      while (k >= (1 << count)) {
        sum += k / (1 << count);
        k = k - (k / (1 << count)) * (1 << count);
      }
      count--;
    }
    printf("%d\n", sum);
  }
}
