#include <bits/stdc++.h>
using namespace std;
int arr[500005];
int arr2[500005];
void solve() {
  int n, m;
  cin >> n >> m;
  if (n >= m) {
    cout << abs(n - m) << "\n";
    return;
  }
  int p = 0, a = 0;
  while (n < m) {
    if (m % 2 == 0) {
      m /= 2;
      ++p;
    } else {
      ++m;
      ++a;
    }
  }
  cout << a + p + n - m;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n = 1;
  for (int i = 0; i < n; i++) {
    solve();
  }
}
