#include <bits/stdc++.h>
using namespace std;
int visited[100005];
struct node {
  int x;
  int step;
};
queue<node> qq;
int main() {
  int i, j, k, l, m, n, x, s;
  node now;
  scanf("%d%d", &n, &m);
  now.x = n;
  now.step = 0;
  qq.push(now);
  while (!qq.empty()) {
    now = qq.front();
    node temp;
    qq.pop();
    if (visited[now.x] == 1 || now.x > 10000 || now.x < 1)
      continue;
    else
      visited[now.x] = 1;
    if (now.x - 1 == m) {
      printf("%d\n", now.step + 1);
      return 0;
    } else {
      temp = now;
      temp.x = temp.x - 1;
      temp.step++;
      qq.push(temp);
    }
    if (now.x * 2 == m) {
      printf("%d\n", now.step + 1);
      return 0;
    } else {
      temp = now;
      temp.x = temp.x * 2;
      temp.step++;
      qq.push(temp);
    }
  }
  return 0;
}
