#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define ff first
#define ss second
#define ii pair<int,int>
#define vii vector<ii>
#define INF 1000000000
#define mod 1000000007
#define endl "\n"
#define ll long long
#define int ll
#define ull unsigned long long
#define ld long double
const double PI = (2.0 * acos(0.0));
#define cz(x) 63 - __builtin_clzll(x)
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void INPUT()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

map<int, int> cnt;
int X, Y;
int solve(int now)
{
	if (now <= X)
		return X - now;
	if (cnt.count(now))
		return cnt[now];
	int res = now - X;
	if (now % 2 == 0)
		res = min(res, solve(now / 2) + 1);
	else
		res = min(res, 1 + min(solve(now - 1), solve(now + 1)));
	return cnt[now] = res;
}

void Tmain()
{
	cin >> X >> Y;
	cout << solve(Y);
}

signed main()
{
	FIO
	INPUT();

	int T = clock();
	int t = 1;
	for (int tc = 1; tc <= t; tc++)
	{
		Tmain();
	}
	cerr << "\n\nTIME: " << (double)(clock() - T) / CLOCKS_PER_SEC << " sec\n";
	T = clock();
	return 0;
}
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, s, n) for(int i = (s); i < int(n); i++)
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
template <class T> ostream &operator << (ostream &o, const vector<T> &v) //vectorの中身を見る
{o << "{"; for(int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", ":"") << v[i]; o << "}"; return o;}
void map_p(map<int, int> &d){cout << "map: "; for(auto a : d){cout << "{" << a.first << ":" << a.second << "}, ";} cout << endl;} //mapの中身を見る
void set_p(set<int> &d){cout << "set: "; for(int a : d){cout << a << ", ";} cout << endl;} //setの中身を見る

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    char s, t;
    cin >> s >> t;
    if(s == 'Y'){
        if('a' <= t and t <= 'z') t -= 'a' - 'A';
        else if('A' <= t and t <= 'Z') t += 'a' - 'A';
    }
    cout << t << endl;
    return 0;
}