#include <bits/stdc++.h>
using namespace std;
long long i, k, z, f, n, m, e[30000], g[30000];
int main() {
  cin >> n >> m;
  if (m < n) {
    cout << n - m << endl;
    return 0;
  }
  for (i = 0; i < 30000; i++) e[i] = 1000000;
  f = 0;
  g[f++] = m;
  e[m] = 0;
  while (k < f) {
    z = g[k];
    if (z % 2 == 0) {
      if (e[z / 2] > e[z] + 1) {
        e[z / 2] = e[z] + 1;
        g[f++] = z / 2;
      }
    }
    if (z + 1 < 30000) {
      if (e[z + 1] > e[z] + 1) {
        e[z + 1] = e[z] + 1;
        g[f++] = z + 1;
      }
    }
    k++;
  }
  cout << e[n];
  return 0;
}
