#include <bits/stdc++.h>
using namespace std;
int n, m, vis[100005];
int main() {
  scanf("%d%d", &n, &m);
  queue<int> Q;
  Q.push(n);
  vis[n] = 1;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    if (u && !vis[u - 1]) Q.push(u - 1), vis[u - 1] = vis[u] + 1;
    if (u * 2 <= 1E5 && !vis[u * 2]) Q.push(u * 2), vis[u * 2] = vis[u] + 1;
  }
  printf("%d", vis[m] - 1);
  return 0;
}
