#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;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define BS(v,n) binary_search(v.begin(),v.end(),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater <ll>())
#define uni(v) v.resize(unique(v.begin(),v.end())-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)
 

int main(){

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt	
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	 #endif
    FAST
//	PRECISE

char s,t;
cin>>s>>t;
if(s=='Y')cout<<(char)toupper(t);
else cout<<(char)tolower(t);

return 0;
 }



		