// abc188F.cpp
#include <iostream>
#include <vector>
#include <map>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
ll x;
map<ll, ll> memo;
ll f(ll y) {
    if (y == 1)return abs(x - y);
    if (memo.find(y) != memo.end()) return memo[y];
    if (y % 2 == 0) {
        return memo[y] = min(f(y / 2) + 1, abs(y - x));
    }
    else {
        return memo[y] = min(min(f(y + 1) + 1,f(y - 1) + 1),abs(y - x));
    }
}
int main()
{
    ll y;
    cin >> x >> y;
    cout << f(y) << endl;
    return 0;
}

#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include<time.h>
using namespace std;

//int N=1;
int P[11] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
int binary(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		//ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
int rev(int original)
{
	int reversed = 0;

	while (original > 0) {
		reversed = original % 10 + reversed * 10;
		original = original / 10;
	}
	return reversed;
}
int gcd(int x, int y) {
	if (x < y) swap(x, y);

	while (y > 0) {
		int r = x % y;
		x = y;
		y = r;
	}
	return x;
}

int main() {
	vector<char>s(12);
	for (int i = 0;i < 12;i++) {
		cin >> s.at(i);
	}
	int cou = 0;
	for (int i = 0;i < 9;i++) {
		if (s.at(i) == 'Z' && s.at(i + 1) == 'O' && s.at(i + 2) == 'N' && s.at(i + 3) == 'e') {
			cou++;
		}
	}
	cout << cou;
}