#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL M;
map<LL, LL> memo;
LL solve(LL N) {
    if (N == M) return 0;
    if (N-M<M-(N/2)+1) return abs(N-M);
    if (memo.count(N)) return memo[N];
	if (N < M) return M - N;
    LL l2 = (N/2)*2;
    LL r2 = ((N+1)/2)*2;

    LL res = 1e18;
    if (N < res) res = N;
    res = min(res, llabs(l2-N) + 1 + solve(l2/2));
    res = min(res, llabs(r2-N) + 1 + solve(r2/2));

	memo[N] = res;

    return res;
}

int main() {
	LL N;
	cin >> M >> N;
	cout << solve(N) << "\n";
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<list>
#include<string.h>
#include<math.h>
#include<set>
#include<string>
#include<queue>
#include<map>
#include<unordered_map>
#include<stack>
//#include<unordered_set>
//#pragma GCC optimize (3)
 
//#define segmenttree true
 
#ifdef segmenttree
#define lc (rt<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#endif
 
#define reg register
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<double, double> pdd; 
typedef pair<char, char> pcc;
typedef pair<ll, bool> plb;
 
const int MAX = 2005;
const ll INF = 1e10;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535;
const double EPS = 1e-5;

ll n, m, a, Sum;

inline ll pow_mod(ll a, ll b, ll mod){
    ll ans = 1;
    a %= mod;
    while(b)
    {
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

inline ll inv(ll num, ll mod){
    return pow_mod(num, mod - 2, mod) % mod;
}

ll C(ll x, ll y){
	ll temp = 1;
	for(int i = 1; i <= y; ++i){
		temp = temp * (x - i + 1) % MOD;
		temp = temp * inv(i, MOD) % MOD;
	}
	return temp;
}

int main(){
//	ios::sync_with_stdio(false);
	scanf("%lld %lld", &n, &m);
	for(int i = 1; i <= n; ++i){
		scanf("%lld", &a);
		Sum += a;
	}
	printf("%lld", C(m + n, n + Sum));
	return 0;
}