#include <bits/stdc++.h>
using namespace std;
int a[20007], m;
void parc(int x, int pas) {
  if ((x < 1) || (x > 20007) || (a[x] <= pas)) return;
  a[x] = pas;
  parc(x - 1, pas + 1);
  parc(2 * x, pas + 1);
}
int main() {
  int n, i, j, x, y;
  cin >> n >> m;
  for (i = 0; i <= 20006; ++i) a[i] = 2000000000;
  parc(n, 0);
  cout << a[m];
  return 0;
}
