#include <bits/stdc++.h>
using namespace std;
long long int a[100000], n, m;
vector<long long int> adj[100000];
long long int level[100000];
bool vis[100000];
long long int bfs(long long int s, long long int m) {
  queue<long long int> q;
  q.push(s);
  level[s] = 0;
  vis[s] = true;
  while (!q.empty()) {
    long long int p = q.front();
    q.pop();
    for (long long int i = 0; i < adj[p].size(); i++) {
      if (vis[adj[p][i]] == false) {
        level[adj[p][i]] = level[p] + 1;
        q.push(adj[p][i]);
        vis[adj[p][i]] = true;
      }
    }
  }
  return level[m];
}
void makegraph(long long int y) {
  queue<long long int> q;
  q.push(y);
  a[y] = 1;
  while (!q.empty()) {
    if (y >= 1) {
      if (a[y - 1] == 0) {
        adj[y].push_back(y - 1);
        q.push(y - 1);
        a[y - 1] = 1;
      }
    }
    if (2 * y >= 0 && 2 * y < 2 * m) {
      if (a[2 * y] == 0) {
        adj[y].push_back(2 * y);
        q.push(2 * y);
        a[2 * y] = 1;
      }
    }
    q.pop();
    y = q.front();
  }
}
int main() {
  int i, j;
  memset(a, 0, sizeof(a));
  cin >> n >> m;
  makegraph(n);
  cout << bfs(n, m);
}
