#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (n >= m) {
    cout << n - m << endl;
    exit(0);
  } else {
    int sum = 0;
    while (m > n) {
      if (m % 2 == 0) {
        m /= 2;
        sum++;
        continue;
      } else {
        m += 1;
        m /= 2;
        sum += 2;
        continue;
      }
    }
    cout << sum + n - m << endl;
    exit(0);
  }
}
