#include <array>
#include <cstddef>
#include <cstdint>

constexpr std::size_t bsr64(std::uint64_t c) noexcept {
#ifdef __GNUC__
  return 63 - __builtin_clzll(c);
#else
  constexpr std::array<std::size_t, 64> table = {
      0,  1,  2,  7,  3,  13, 8,  27, 4,  33, 14, 36, 9,  49, 28, 19,
      5,  25, 34, 17, 15, 53, 37, 55, 10, 46, 50, 39, 29, 42, 20, 57,
      63, 6,  12, 26, 32, 35, 48, 18, 24, 16, 52, 54, 45, 38, 41, 56,
      62, 11, 31, 47, 23, 51, 44, 40, 61, 30, 22, 43, 60, 21, 59, 58};
  c |= c >> 1;
  c |= c >> 2;
  c |= c >> 4;
  c |= c >> 8;
  c |= c >> 16;
  c |= c >> 32;
  return table[((c >> 1) + 1) * 0x218A7A392DD9ABFULL >> 58 & 0x3F];
#endif
}

#include <array>
#include <cstddef>
#include <cstdint>

constexpr std::size_t bsf64(const std::uint64_t c) noexcept {
#ifdef __GNUC__
  return __builtin_ctzll(c);
#else
  constexpr std::array<std::size_t, 64> table = {
      0,  1,  2,  7,  3,  13, 8,  27, 4,  33, 14, 36, 9,  49, 28, 19,
      5,  25, 34, 17, 15, 53, 37, 55, 10, 46, 50, 39, 29, 42, 20, 57,
      63, 6,  12, 26, 32, 35, 48, 18, 24, 16, 52, 54, 45, 38, 41, 56,
      62, 11, 31, 47, 23, 51, 44, 40, 61, 30, 22, 43, 60, 21, 59, 58};
  return table[(c & ~c + 1) * 0x218A7A392DD9ABFULL >> 58 & 0x3F];
#endif
}

#include <algorithm>
#include <array>
#include <cstdint>
#include <iostream>
#include <limits>

int main() {
  using i64 = std::int64_t;
  using u64 = std::uint64_t;

  const auto distance = [](u64 a, u64 b) { return a < b ? b - a : a - b; };

  u64 X, Y;
  std::cin >> X >> Y;

  if (X >= Y) {
    std::cout << X - Y << std::endl;
    return 0;
  }

  u64 ans = std::numeric_limits<u64>::max();

  const auto update = [&](u64 t) { ans = std::min(ans, t); };

  const auto check = [&](u64 step) {
    const u64 ctz = bsf64(Y);
    if (step <= ctz) {
      update(distance(X, Y >> step) + step);
      return;
    }
    step -= ctz + 1;
    const u64 Y_ = Y >> (ctz + 1);

    const u64 stm = ~(~u64(0) << step);

    struct elem_t {
      u64 cost;
      u64 mask;
    };

    const auto base = [&](const u64 mat_base, const u64 add) {
      std::array<std::array<elem_t, 3>, 3> mat = {};

      for (int i = 0; i < 3; ++i) {
        mat[i][std::min(i + 1, 2)].mask |= mat_base & stm;
        mat[i][std::max(i - 1, 0)].mask |= ~mat_base & stm;
        mat[i][i].mask |= ~stm;
      }

      mat[0][1].cost = mat_base & stm;
      mat[1][2].cost = mat_base & stm;

      const auto iterate = [&](const u64 w, const u64 mask) {
        std::array<std::array<elem_t, 3>, 3> sq = {};
        for (int i = 0; i < 3; ++i) {
          for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
              u64 temp = (mat[i][j].mask & mask) & (mat[j][k].mask >> w & mask);
              temp |= temp << w;
              sq[i][k].mask |= temp;
              sq[i][k].cost |=
                  ((mat[i][j].cost & mask) + (mat[j][k].cost >> w & mask)) &
                  temp;
            }
          }
        }
        mat = sq;
      };
      u64 w = 1;
      for (; w < step; w *= 2) {
        iterate(w, ~u64(0) / ((u64(1) << w) + 1));
      }
      u64 res = 0;
      for (int i = 0; i < 3; ++i) {
        res |= mat[1][i].cost & (w * 2 - 1);
      }
      update(res + ctz + 2 + step + distance(X, (Y_ >> step) + add));
    };
    base(Y_, 0);
    base(~Y_, 1);
  };

  const i64 bsrY = bsr64(Y);
  for (i64 i = bsrY - 2; i <= bsrY + 1; ++i) {
    if (0 <= i && i < 64) {
      check(i);
    }
  }
  const i64 diff = bsrY - bsr64(X);
  for (i64 i = diff - 1; i <= diff + 1; ++i) {
    if (0 <= i && i < 64) {
      check(i);
    }
  }

  std::cout << ans << std::endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};


void solve(int tc){
	lld x,y;
	cin >> x  >> y;
	if(x==y){
		printf("0");
	}else if(y<x){
		printf("%lld",x-y);
	}else{
		lld rans = 1e18;
		lld k = 1,e = 0;
		while(k*x<=3e18){
			lld tot = abs(y - k*x);
			lld ans = e + (tot/k);
			tot %= k;
			while(tot){
				if((tot&3)==3){
					tot++;
					ans++;
				}
				else if(tot&1){
					tot--;
					ans++;
				}
				tot /= 2;
			}
			rans = min(rans,ans);
			k *= 2;
			e++;
		}
		printf("%lld\n",rans);
	}
}


int main(void){
	/*
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	*/
	int tc = 1;
	/*
		scanf("%d",&tc);
	*/
	for(int test_number=1;test_number<=tc;test_number++){
		solve(test_number);
	}
	return 0;
}