#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <list>
#include <unordered_set>
//#include <atcoder/convolution>
//#include <atcoder/modint>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
#define bug4(x, y, z, w) cout<<"zdongdebug4: "<<x<<" "<<y<<" "<<z<<" "<<w<<endl;
using namespace std;
//using Modint = atcoder::modint998244353;
typedef long long ll;
void ex_gcd(ll a,ll b, ll& d,ll& x,ll& y){
  if(!b) {d=a;x=1;y=0;}
  else   {	ex_gcd(b,a%b,d,y,x);	y-=a/b*x;}
}
ll inv(ll a,ll n)  {
  ll d,x,y;	ex_gcd(a,n,d,x,y);
  return d==1?(x%n+n)%(n/d):-1;
}
ll gcd(ll x, ll y){
  if(y==0)return x;
  return gcd(y, x%y);
}

const int maxn = 200005;
const int mod = 1000000007;

vector<int>e[maxn];
int d[maxn], pnt[maxn];
int ans[maxn];
bool onit[maxn];

void bfs(int x) {
  memset(d, -1, sizeof(d));
  queue<int>q;
  d[x] = 0;
  pnt[x] = 0;
  q.push(x);
  while(!q.empty()){
    int x = q.front();
    q.pop();
    for(int i=0;i<e[x].size();i++){
      int y = e[x][i];
      if(d[y]!=-1)continue;
      d[y] = d[x] + 1;
      pnt[y] = x;
      q.push(y);
    }
  }
}

int ret;
void dfs(int x,int fa){
  ret++;
  ans[x] = ret;
  int idx = -1;
  for(int i=0;i<e[x].size();i++){
    int y = e[x][i];
    if(y==fa)continue;
    if(onit[y]){
      idx = y;
      continue;
    }
    dfs(y, x);
    ret++;
  }
  if(idx!=-1){
    dfs(idx, x);
    ret++;
  }
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  cin>>n;
  for(int i=1;i<n;i++){
    int x,y;
    cin>>x>>y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  bfs(1);
  int mx=-1, idx;
  for(int i=1;i<=n;i++){
    if(mx<d[i]){
      mx = d[i];
      idx = i;
    }
  }
  bfs(idx);
  mx = -1;
  for(int i=1;i<=n;i++){
    if(mx<d[i]){
      mx = d[i];
      idx = i;
    }
  }
  int cur = idx;
  while(cur!=0){
    onit[cur] = 1;
    cur = pnt[cur];
  }
  ret = 0;
  dfs(idx, 0);
  for(int i=1;i<n;i++){
    cout<<ans[i]<<" ";
  }
  cout<<ans[n]<<endl;
  return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))
#define all(v) v.begin(),v.end()
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#ifdef VAMP
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif

const int N = 200005;
vector<LL>g[N];
LL n , U[N] , V[N] , q;
LL par[N];
LL ara[N] , add[N];
void dfs(LL node,LL pre)
{
    par[node] = pre;
    for(LL i : g[node]){
        if(i == pre)continue;
        dfs(i,node);
    }
}

void dfs2(LL node,LL pre,LL has){
    has = has + add[node];
    ara[node] = has;
    for(LL i : g[node]){
        if(i == pre)continue;
        dfs2(i,node,has);
    }
}
int main()
{
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    cin >> n;
    for(LL i = 1;i < n;i++){
        LL u , v;
        cin >> U[i] >> V[i];
        u = U[i];
        v = V[i];
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1,0);

    LL total = 0;
    cin >> q;
    while(q--){
        LL tp , e , x;
        cin >> tp >> e >> x;

        if(tp == 1){
            LL a = U[e];
            LL b = V[e];

            if(par[a] == b){
                add[a] += x;
            }else{
                total += x;
                add[b] -= x;
            }
        }else{
            LL a = V[e];
            LL b = U[e];
            if(par[a] == b){
                add[a] += x;
            }else{
                total += x;
                add[b] -= x;
            }
        }
//        FOR(i,1,n)cout << add[i] << "\n";
//        cout << endl;
    }

    dfs2(1,0,total);
    FOR(i,1,n)cout << ara[i] << "\n";

    #ifdef VAMP
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}


#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define swap(a,b) (a^=b^=a^=b)
#define ll long long int
#define ull unsigned long long int
#define uint unsigned int
#define format(a) memset(a,0,sizeof(a))
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define dec(x,y,z) for(int x=y;x>=z;x--)
#define mst(x) memset(x,0,sizeof(x))
#define mid ((l+r)>>1)
const int maxn=1e5+10;
inline int read()
{
    int ans=0;
    char last=' ',ch=getchar();
    while(ch<'0'|ch>'9')last=ch,ch=getchar();
    while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
    if(last=='-')ans=-ans;
    return ans;
}
int n;
string s;
int a[105];
int b[maxn][105];
int sm[105],snum[105],bi[105],bnum[105];
bool check(int cur)
{
    rep(i,1,n)
    {
        int val=a[i]/cur;
        int les=a[i]-a[i]/cur*cur;
        rep(j,1,cur)
        {
            b[j][i]=val;
            if(j<=les)b[j][i]++;
        }
    }
    rep(i,1,n-1)
    {
        bool ok;
        if(s[i-1]=='<')ok=0;
        else ok=1;
        rep(j,1,cur)
        {
            if(!ok&&b[j][i]>=b[j][i+1])return 0;
            if(ok&&b[j][i]<=b[j][i+1])return 0;
        }
    }
    return 1;
}
int main()
{
    cin>>n>>s;
    n++;
    rep(i,1,n)cin>>a[i];
    int l=1,r=10000;
    while(l+1<r)
    {

        if(check(mid))l=mid;
        else r=mid;
        //cout<<l<<" "<<r<<endl;
    }
    //cout<<check(2)<<endl;
    if(check(r))l=r;
    check(l);
    cout<<l<<"\n";
    rep(i,1,l)
    {
        rep(j,1,n)cout<<b[i][j]<<" ";
        cout<<"\n";
    }

    return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  vector<int> a(n + 1);
  for(int i = 0; i <= n; i++){
    cin >> a[i];
  }

  vector<int> d(n);
  int min_d = INF;
  for(int i = 0; i < n; i++){
    d[i] = abs(a[i] - a[i + 1]);
    min_d = min(min_d, d[i]);
  }

  int k = min_d;
  vector<vector<int>> b(k, vector<int>(n + 1));
  for(int i = 0; i <= n; i++){
    for(int j = 0; j < k; j++)b[j][i] = a[i] / k;
    for(int j = 0; j < a[i] % k; j++)b[j][i] += 1;
  }

  cout << k << endl;
  for(int i = 0; i < k; i++){
    for(int j = 0; j <= n; j++){
      cout << b[i][j] << ' ';
    }
    cout << endl;
  }
  return 0;
}


#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include <bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
#define gi(x) scanf("%d",&x)
#define gi2(x,y) scanf("%d%d",&x,&y)
#define gll(x) scanf("%lld",&x)
#define gll2(x,y) scanf("%lld%lld",&x,&y)
using namespace std;
const double eps=1e-8;
typedef long long ll;
const int MAXN=205;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
using namespace std;
int a[MAXN];

int dp[MAXN][40005];
vector< pair<int,int> >b[MAXN][40005];
vector<int> last[MAXN][40005];
int main(){

	int n;
	cin>>n;
	int sum=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]%=200;
		sum+=a[i];
	}
	dp[0][0]=1;
	last[0][0].push_back(-1);
	for(int i=1;i<=n;i++){
		for(int j=0;j<200;j++){
			dp[i][j]=dp[i-1][j];
			if(dp[i-1][j]>=1&&last[i-1][j].size()){
				last[i][j].push_back(last[i-1][j][0]);
			}
			if(dp[i-1][(j-a[i]+200)%200]>=1){
				dp[i][j]=dp[i-1][(j-a[i]+200)%200];
				last[i][j].push_back(i);
			}
			if(j!=0&&last[i][j].size()>=2){
				stack<int>s[2];
				for(int k=0;k<2;k++){
					int t=last[i][j][k];
					int m=j;
					while(1){
						s[k].push(t);
						m-=a[t];
						m+=200;m%=200;
						if(last[t-1][m][0]!=-1)
							t=last[t-1][m][0];
						else{
							break;
						}
					}
				}
				printf("Yes\n");
				for(int k=0;k<2;k++){
					cout<<s[k].size();
					while(s[k].size()){
						cout<<" "<<s[k].top();
						s[k].pop();
					}
					cout<<endl;
				}
				return 0;
			}
		}
	}
	printf("No\n");
//	for(int i=1;i<=n;i++){
//		for(int j=0;j<=sum;j++){
//			if(dp[i][j]){
//				cout<<i<<' '<<j<<' '<<dp[i][j]<<endl;
//			}
//		}
//	}

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto &&e : A) {
    cin >> e;
  }
  vector<vector<int>> X(200);
  for (int i = 0; i < N; i++) {
    X[A[i] % 200].emplace_back(i);
  }
  for (int i = 0; i < 200; i++) {
    if ((int)X[i].size() >= 2) {
      cout << "Yes" << '\n';
      cout << 1 << ' ' << X[i][0] + 1 << '\n';
      cout << 1 << ' ' << X[i][1] + 1 << '\n';
      return 0;
    }
  }
  vector<bitset<200>> Y(200);
  for (int i = 0; i < N; i++) {
    auto Z = Y;
    if (Y[A[i] % 200].any()) {
      cout << "Yes" << '\n';
      cout << 1 << ' ' << i + 1 << '\n';
      vector<int> c;
      for (int j = 0; j < N; j++) {
        if (Y[A[i] % 200][j]) c.emplace_back(j);
      }
      cout << c.size() << ' ';
      for (const auto &e : c) {
        cout << e + 1 << (&e == &c.back() ? '\n' : ' ');
      }
      return 0;
    }
    if (Y[0].any()) {
      cout << "Yes" << '\n';
      cout << 1 << ' ' << i + 1 << '\n';
      vector<int> c;
      for (int j = 0; j < N; j++) {
        if (Y[0][j] || i == j) c.emplace_back(j);
      }
      cout << c.size() << ' ';
      for (const auto &e : c) {
        cout << e + 1 << (&e == &c.back() ? '\n' : ' ');
      }
      return 0;
    }
    Z[A[i] % 200][i] = 1;
    for (int j = 0; j < 200; j++) {
      if (Y[j].none()) continue;
      if (Y[(j + A[i]) % 200].any()) {
        bitset<200> b = Y[(j + A[i]) % 200], c = Y[j];
        c[i] = 1;
        for (int k = 0; k < N; k++) {
          if (b[k] && c[k]) {
            b[k] = 0;
            c[k] = 0;
          }
        }
        if (b.any() && c.any()) {
          cout << "Yes" << '\n';
          vector<int> bb, cc;
          for (int k = 0; k < N; k++) {
            if (b[k]) bb.emplace_back(k);
            if (c[k]) cc.emplace_back(k);
          }
          cout << bb.size() << ' ';
          for (const auto &e : bb) {
            cout << e + 1 << (&e == &bb.back() ? '\n' : ' ');
          }
          cout << cc.size() << ' ';
          for (const auto &e : cc) {
            cout << e + 1 << (&e == &cc.back() ? '\n' : ' ');
          }
          return 0;
        }
      }
      Z[(j + A[i]) % 200] = Y[j];
      Z[(j + A[i]) % 200][i] = 1;
    }
    Y = Z;
  }
  cout << "No" << '\n';
  return 0;
}


#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PLI = pair<long long, long long>;
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
//ミョ(-ω- ?)
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll n, k;
    cin >> n >> k;
    map<ll, ll> mp;
    rep(i, n) {
        ll in;
        cin >> in;
        mp[in]++;
    }
    ll res = 0;
    ll recent = LONG_LONG_MAX;
    rep(i, n + 1) {
        // if (mp[i] >= k) continue;
        if (mp[i] == 0) break;
        chmin(recent, mp[i]);
        res += max(0ll, i + 1) * min(k, recent) - max(0ll, i) * min(k, recent);
        // recent =mp[i];
    }
    cout << res << "\n";
    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(int i=cc;i>=n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;

const vector<int> dx = {1, 0, -1,  0};
const vector<int> dy = {0, 1,  0, -1};

const vector<int> dx2 = {1, 1,  1, 0,  0, 0, -1, -1, -1};
const vector<int> dy2 = {1, 0, -1, 1, -1, 0,  1,  0, -1};

const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
const ll mod2 = 998244353;

const ll MAX = 1000000;
const int MOD = 1000000007;
const ll big = (1ll<<60);

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }

int main(){
   int a, b;
   cin >> a >> b;
   vector<int>ans;
   if(a>=b){
     int sum = 0;
     rep(i, 0, a){
       ans.push_back(i+1);
       sum += (i+1);
     }
     rep(i, 0, b-1){
       ans.push_back(-(i+1));
       sum -= (i+1);
     }
     ans.push_back(-sum);
   }else{
     int sum = 0;
     rep(i, 0, b){
       ans.push_back(-(i+1));
       sum += (i+1);
     }
     rep(i, 0, a-1){
       ans.push_back(i+1);
       sum -= (i+1);
     }
     ans.push_back(sum);
   }
   for(auto i:ans)cout << i << " ";
   cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int a, b, w;
  cin >> a >> b >> w;

  w *= 1000;

  int min_orange = -1;
  int max_orange = -1;

  if (w % b == 0) min_orange = w / b;
  else if ((w / b + 1) * b - w <= (b - a) * (w / b + 1)) min_orange = w / b + 1;

  if (w % a == 0) max_orange = w / a;
  else if ((w / a) * a - w <= (b - a) * (w / a)) max_orange = w / a;

  //cout << min_orange << endl;

  if (min_orange == -1 || max_orange == -1) cout << "UNSATISFIABLE" << endl;
  else cout << min_orange << " " << max_orange << endl;

  return 0;
}

#include <bits/stdc++.h>
#define int long long
using namespace std;

int cx[1000005];
int ci[1000005];

signed main(){
int a,b,w;
memset(ci,0X3f,sizeof(ci));
memset(cx,0,sizeof(cx));
ci[0] = 0;
cin>>a>>b>>w;
w = w*1000;

int judge = 0;
for(int i=a;i<=b;i++)
    for(int j=i;j<=w;j++){
    cx[j] = max(cx[j],cx[j-i]+1);
    ci[j] = min(ci[j],ci[j-i]+1);

}
//4557430888798830399

if(ci[w]==4557430888798830399)
    cout<<"UNSATISFIABLE";
else
    cout<<ci[w]<<" "<<cx[w];

}


#include<bits/stdc++.h>

using namespace std;

/**templates**/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;

#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sull(x) scanf("%llu",&x)
#define sf(x) scanf("%lf",&x)
#define ss(x) scanf(" %s",x)
#define sc(x) scanf(" %c",&x)
#define pi acos(-1.0)
#define pb push_back
#define aa first
#define bb second
#define sz(x) (ll)(x).size()
#define cas printf("Case %lld: ",++t)
#define casline printf("Case %lld:\n",++t)
//#define cas cout<<"Case "<<++t<<": "
//#define casline cout<<"Case "<<++t<<":"<<endl;
#define distance(x1,y1,x2,y2)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
#define endl "\n"
#define bug cout<<"bugggggggggggg "<<endl;
#define fast ios_base::sync_with_stdio(0);cin.tie(nullptr); ///no printf/scanf
#define clean fflush(stdout)

const ll mod = 1000000007;
const ll inf = 1LL<<62;
const ll mx = 100005;
const double eps = 1e-10;

ll dx[10]={1,0,-1,0};
ll dy[10]={0,-1,0,1};
///ll dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; /// 8 Direction
///ll dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; /// Knight Direction

ll power(ll a,ll b)
{
    if(b==0)return 1;
    ll x=power(a,b/2);
    x=x*x;
    if(b%2)x=x*a;
    return x;
}

ll bigmod(ll a,ll b)
{
    if(b==0)return 1;
    ll x=bigmod(a,b/2)%mod;
    x=(x*x)%mod;
    if(b%2)x=(x*a)%mod;
    return x;
}

ll Set(ll N,ll pos){return N=N | (1LL<<pos);}
ll reset(ll N,ll pos){return N= N & ~(1LL<<pos);}
bool check(ll N,ll pos){return (bool)(N & (1LL<<pos));}

/**
        ...ENDING OF TEMPLATE...
*/

ll arr[1005],brr[1005];
ll dp[1005][1005],n,m;

ll solve(ll i,ll j)
{
//    if(i>n and j>m)
//        return 0;
    if(i>n)
        return (m-j+1);
    if(j>m)
        return (n-i+1);
    ll &ret=dp[i][j];
    if(ret!=-1)
        return ret;
    ret=(arr[i]!=brr[j])+solve(i+1,j+1);
    ret=min(ret,solve(i+1,j)+1);
    ret=min(ret,solve(i,j+1)+1);
    return ret;
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    fast; ///no printf/scanf
    /** Use "long double"(%Lf) instead of double for precision safety*/
    ll tst,a,b,c,k,res=0,ans=0,t=0;
    sl(n),sl(m);
    for(ll i=1;i<=n;i++)
    {
        sl(arr[i]);
    }
    for(ll i=1;i<=m;i++)
    {
        sl(brr[i]);
    }
    memset(dp,-1,sizeof(dp));
    res=solve(1,1);
    cout<<res<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
ll b,c,ans;
int main(){
	b=read(),c=read();
	if(b==0) ans=c;
	else if(c==1) ans=2;
	else if(2*abs(b)>=c) ans=2*c-1;
	else{
		ans=c+2*abs(b);
		if(b>0) --ans;
	}
	printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")

using namespace std;
using namespace __gnu_pbds;

#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int, int>>
#define vvi vector<vi>
#define vvii vector<vii>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define loop(_) for (int __ = 0; __ < (_); ++__)
#define forn(i, n) for (int i = 0; i < n; ++i)
#define pb push_back
#define f first
#define s second
#define sz(_) ((int)_.size())
#define all(_) _.begin(), _.end()
#define uni(_) unique(_)
#define lb lower_bound
#define ub upper_bound
#define si set<int>
#define ms multiset<int>
#define qi queue<int>
#define pq prioriry_queue<int>
#define mi map<int, int>
#define inc(i, l, r) for (int i = l; i <= r; i++)
#define dec(i, l, r) for (int i = l; i >= r; i--)

using lll = __int128;
using ll = long long;
using ld = long double;

const int N = 1e5 + 7;
const ll mod = 1e9 + 7;
const ll inf = 2e18;

auto ra = [] {char *p = new char ; delete p ; return ll(p) ; };
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * (ra() | 1));
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> os;

int n;

void nor(pll &pr)
{
       if (pr.f > pr.s)
              swap(pr.f, pr.s);
}

ll sum(pll x) { return x.s - x.f + 1; }

int main()
{
       ios_base::sync_with_stdio(0);
       cin.tie(0);
#ifndef ONLINE_JUDGE
       freopen("in.in", "r", stdin);
#endif

       ll b, c;
       cin >> b >> c;

       pair<ll, ll> in1, in2;
       in1 = {b - (c / 2), b + (c - 2) / 2};
       in2 = {-b - (c - 1) / 2, -b + (c - 1) / 2};
       nor(in1), nor(in2);
       ll ans = sum(in1) + sum(in2) - max(0ll, sum({max(in1.f, in2.f), min(in1.s, in2.s)}));
       cout << ans;
       return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];

    int res1=0,res3=-1*INF;
    ld res2=0.0;

    rep(i,n) res1+=abs(a[i]);
    rep(i,n) res2+=a[i]*a[i]; res2=sqrt(res2);
    rep(i,n) res3=max(res3,abs(a[i]));
    cout<<res1<<endl<<res2<<endl<<res3<<endl;
}

#include <bits/stdc++.h>
using namespace std;
using INT = long long int;
using VINT = vector<INT>;
using VVINT = vector<VINT>;
using DBL = long double;
const int BX = 1;
INT N, M;
map<INT, VINT> E;
void init() {
    cin >> N >> M;
    for ( INT ix = 0 + BX; ix < M + BX; ix++ ) {
        INT a, b;
        cin >> a >> b;
        E[ a ].push_back( b );
    }
}
void dfs( const INT id, set<INT>& visited ) {
    if ( visited.count( id ) > 0 ) {
        return;
    }
    visited.insert( id );
    for ( auto it = E[ id ].cbegin(); it != E[ id ].cend(); it++ ) {
        dfs( *it, visited );
    }
}
void kick() {
    init();
    INT res = 0;
    for ( INT id = 0 + BX; id < N + BX; id++ ) {
        set<INT> visited;
        dfs( id, visited );
        res += visited.size();
    }
    cout << res << endl;
}
int main() {
    kick();
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define endl "\n"
#define endly " "
#define int long long
#define sz(x) ((int)x.size())
#define len(x) ((int)x.length())
#define ff first
#define ss second
#define all(x) begin(x), end(x)
#define tc() int test; cin>>test; while(test--)
#define pii pair<int,int>

int32_t main()
{
      ios::sync_with_stdio(false);
      cin.tie(0);
      int a,b,c;
      cin>>a>>b>>c;
      if(a == b)
            cout<<c<<endl;
      else if(a == c)
            cout<<b<<endl;
      else if(b == c)
            cout<<a<<endl;
      else
            cout<<0<<endl;

      return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define each(x,v) for(auto& (x) : (v))
#define f(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define b(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define mem(mat,f) memset(mat, f, sizeof(mat))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define make(a,n) ll *a=new ll[n]();
#define maxq(x) priority_queue<x>
#define minq(x) priority_queue<x,vector<x>,greater<x>>
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
const ll INF = 1LL << 60;

bool isSquare(long double x){
    if (x >= 0) {
        long long sr = sqrt(x);
        return (sr * sr == x);
    }
    return false;
}

int countDigit(long long n){
    if (n == 0)
        return 0;
    return 1 + countDigit(n / 10);
}

int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

inline ll max(ll a1,ll a2){
    if(a1>a2){
        return a1;
    }else{
        return a2;
    }
}

inline ll min(ll a1,ll a2){
    if(a1<a2){
        return a1;
    }else{
        return a2;
    }
}

/*int multiply(int x, int res[], int res_size) {
int carry = 0;
for (int i = 0; i < res_size; i++) {
    int prod = res[i] * x + carry;
    res[i] = prod % 10;
    carry = prod / 10;
}
while (carry) {
    res[res_size] = carry % 10;
    carry = carry / 10;
    res_size++;
}
return res_size;
}
ll power(int x, int n){
if(n == 0 ){
    return 1;
}
int res[100000];
int res_size = 0;
int temp = x;
while (temp != 0) {
    res[res_size++] = temp % 10;
    temp = temp / 10;
}
for (int i = 2; i <= n; i++)
    res_size = multiply(x, res, res_size);
ll ans=0;
for (int i = res_size - 1; i >= 0; i--)
    ans=((ans*10)%mod+res[i]%mod)%mod;
return ans%mod;
}*/

ll multiply(ll x, ll res[], ll res_size)
{
    ll carry = 0;

    for (ll i=0; i<res_size; i++)
    {
        ll prod = res[i] * x + carry;
        res[i] = prod % 10;
        carry  = prod/10;
    }

    while (carry)
    {
        res[res_size] = carry%10;
        carry = carry/10;
        res_size++;
    }
    return res_size;
}
ll fact(ll n)
{
    ll res[50005];

    res[0] = 1;
    ll res_size = 1;

    for (ll x=2; x<=n; x++)
    {
        res_size = multiply(x, res, res_size);
    }
    ll a=0;
    for (ll i=res_size-1; i>=0; i--){
        a=((a*10)%mod+res[i])%mod;
    }
    return a%mod;
}

ll pf[505];

void primeFactors(ll n){
    while (n % 2 == 0)
    {
        pf[2]++;
        n = n/2;
    }
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            pf[i]++;
            n = n/i;
        }
    }
    if (n > 2)
        pf[n]++;
}

class node{
public:
    int s;
    int e;
    int p;
};

bool compare(node a1,node a2){

    return a1.e<a2.e;
}

//////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////

int main(){

    fast;

    ll a,b,c;
    cin>>a>>b>>c;

    if(a==b){
        cout<<c<<endl;
    }
    else if(b==c){
        cout<<a<<endl;
    }
    else if(a==c){
        cout<<b<<endl;
    }else{
        cout<<"0"<<endl;
    }

return 0;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

//head

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vi x(n), y(n), z(n);
  rep(i, n) cin >> x[i] >> y[i] >> z[i];
  vvi dist(n, vi(n));
  rep(i, n) {
    rep(j, n) {
      int u = abs(x[i]-x[j]) + abs(y[i]-y[j]) + max(0, z[j]-z[i]);
      dist[i][j] = u;
    }
  }
  vvi dp(1<<n, vi(n, INT_MAX));
  dp[1][0] = 0;
  for(int i = 1; i < (1<<n)-1; i++) {
    rep(j, n) if((i>>j&1) and dp[i][j] != INT_MAX) {
      int now = dp[i][j];
      rep(k, n) if(~i>>k&1) {
        chmin(dp[i|(1<<k)][k], now+dist[j][k]);
      }
    }
  }
  int ans = INT_MAX;
  for(int i = 1; i < n; i++) {
    chmin(ans, dp[(1<<n)-1][i]+dist[i][0]);
  }
  cout << ans << endl;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
//****************************************
// Graph template
//****************************************

// status of edge
template <typename X>
struct Edge{
  int from;
  int to;
  X cost;

  Edge() = default;

  Edge(int from, int to, X cost) : from(from), to(to), cost(cost) {}
};

// status of node
template <typename X>
struct Node{
  int idx;
  vector<Edge<X>> edge;

  Node() = default;

  explicit Node(int idx) : idx(idx) {}
};

template <typename X>
class Graph{
private:
  int n; // number of node
  int m; // number of edge
  vector<Node<X>> node;

  void Init_Node() {
    rep(i,n) node.emplace_back(i);
  }
public:
  explicit Graph(int n) : n(n) {
    Init_Node();
  }

  // edges have no-weight
  Graph(int n, int m, vector<int> from, vector<int> to) : n(n), m(m) {
    Init_Node();
    rep(i,m) {
      add_edge(from[i], to[i]);
      add_edge(to[i], from[i]);
    }
  }

  // edges have weight
  Graph(int n, int m, vector<int> from, vector<int> to, vector<X> cost) : n(n), m(m) {
    Init_Node();
    rep(i,m) {
      add_edge(from[i], to[i], cost[i]);
      add_edge(to[i], from[i], cost[i]);
    }
  }

  void add_edge(int from, int to, X cost = 1) {
    node[from].edge.emplace_back(from, to, cost);
  }

  void Solve() {
    vi d(n, -1);
    d[0] = 0;
    auto dfs = [&](auto self, int v)->void{
      for(auto next: node[v].edge) {
	int w = next.to;
	if(d[w] != -1) continue;
	if(d[v] == next.cost) {
	  d[w] = (d[v] + 1) % n;
	  self(self, w);
	}
	else {
	  d[w] = next.cost;
	  self(self, w);
	}
      }
    };
    dfs(dfs, 0);
    rep(i,n) cout << d[i]+1 << "\n";
  }

};

int main()
{
  int n,m; cin >> n >> m;
  vi a(m),b(m),c(m);
  rep(i,m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--; c[i]--;
  }

  Graph<int> gp(n, m, a, b, c);
  gp.Solve();

  return 0;
}


#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pint = pair<int,int>;

int main()
{
	int N;cin >> N;
	int m = N - 1;
	vector<int> A(N);
	for(auto &i: A) cin >> i;
	int ans = 1<<30;

	for(int bit = 0; bit < (1<<m); bit++) {
		vector<int> b = {A[0]};
		for(int i = 0; i < N - 1; i++) {
			if((1 << i) & bit) {
				b.push_back(0);
			}
			b.back() |= A[i + 1];
		}

		int sum = accumulate(b.begin(), b.end(), 0, [](int x, int y){return (x xor y);});

		ans = min(ans, sum);
	}

	cout << ans << endl;

}

#include<bits/stdc++.h>

#define all(k) k.begin(),k.end()

#define repk(i,a, n) for(int i=a;i<=n;i++)
#define rep(i,a, n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define ll  long long
#define ull unsigned long long
#define pci pair<int,int>
#define vc vector<char>
#define vs vector<set<pi>>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vb vector<bool>
#define vpc vector<pci>
#define vvc vector<vc>
#define mi map<int,int>
#define mset map<string,set<char>>
#define umap unordered_map
#define int int64_t
using namespace std;
#define fi first
#define se second
#define mod 1000000007

void sol()
{ int n;
  cin >> n;
  vi a(n);
  rep(i,0,n)cin>>a[i];

  auto deep = [&](auto && deep, int i, int x, int o) -> int {
    if (i == n) return x ^ o;
    return min(deep(deep, i + 1, x, o | a[i]), deep(deep, i + 1, x ^ o, a[i]));
  };
  cout << deep(deep, 0, 0, 0);
}

int32_t main() {

int t=1;
// for(cin>>t;t;t--)
sol();
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
//const int mod=1e9+7;
const int mex=200005;
#define ll long long
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int>
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++)
#define int long long
int power(int a,int b,int mod)
{
	int ans=1,f=a;
	while(b)
	{
		if(b&1ll) ans=ans*f%mod;
		f=f*f%mod;
		b=b>>1ll;
	}
	return ans;
}

signed main()
{
	string s;
    cin>>s;
    int n=sz(s);
    int fr[26]={0},ans=0;
    rfo(i,sz(s)-1,1)
    {
        if(s[i]==s[i-1])
        {
            ans=ans+(n-i-1-fr[s[i]-'a']);
            fo(i,0,26)
            fr[i]=0;
            fr[s[i]-'a']=n-i;
        }
        else fr[s[i]-'a']++;
    }
    cout<<ans<<endl;

}

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define F(i,n) for (int i = 0; i < n; ++i)
#define F1(i,n) for (int i = 1; i <= n; ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define dbgg(x) cerr << #x << " = " << x << ' '
#define T(x) x[pool]
#define mineq(x,y) { if ((x) > (y)) (x) = (y); }
#define maxeq(x,y) { if ((x) < (y)) (x) = (y); }
#define MEOW cout << "meowwwww" << '\n'; system("pause");
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c)
{
	s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n";
	return s;
}

template<typename T>
ostream& operator <<(ostream &s, const pair<int, T> &c)
{
	s << "[ "; cout << c.fi << " , " << c.se << " ] ";
	return s;
}

int n;
string a;

void input()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> a;
}

void solve()
{
	int ok = 0;
	if (a[0] == a[n - 1])
	{
		for (int i = 0; i < n - 1; ++i)
			if (a[i] != a[0] && a[i + 1] != a[0])
				ok = 2;
	} else ok = 1;
	if (ok) cout << ok << '\n';
	else cout << "-1\n";
}

main()
{
	input();
	solve();
}


#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

char win(char a,char b){
    if (a == 'R' && b == 'P') return b;
    if (a == 'P' && b == 'S') return b;
    if (a == 'S' && b == 'R') return b;
    else return a;
}
int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    while(k--){
        s += s;
        string t;
        for(int i = 0;i<2*n;i+= 2){
            t += win(s[i],s[i+1]);
        }
        s = t;
    }
    cout << s[0] << endl;

    }

#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, m, i;
	ll a = 0, b = 0;
	cin >> num >> m;
	string s;
	rep(i, num) {
		cin >> s;
		int x = 0;
		for (char c : s) {
			if (c == '1')
				x++;
		}
		if (x & 1)
			a++;
		else
			b++;
	}
	cout << a * b << "\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using ll = long long;
using ld = long double;

#define mp make_pair

const int p = 998244353;

int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

mt19937 rnd(time(0));

/*
const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}

*/

/*struct DSU
{
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU (int n)
    {
        parent.resize(n);
        sz.resize(n);
        for (int i = 0; i<n; i++) make_set(i);
    }
};*/

int solve(int l, int r, int pos)
{
    return max(r, pos) - min(l, pos);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    int n, l;
    cin>>n>>l;
    vector<int> a(n+2), b(n+2);
    for (int i = 1; i<=n; i++) cin>>a[i];
    for (int i = 1; i<=n; i++) cin>>b[i];
    a[0] = 0; b[0] = 0; a[n+1] = l+1; b[n+1] = l+1;
    vector<int> A;
    for (int i = 0; i<n+1; i++) A.push_back(a[i+1]-a[i]-1);
    vector<int> B;
    for (int i = 0; i<n+1; i++) B.push_back(b[i+1]-b[i]-1);

    a = A; b = B;

    ll ans = 0;

    n++;
    int cur = 0;
    for (int i = 0; i<n; i++) if (b[i]!=0)
    {
        while (cur<n && a[cur]==0) cur++;

        int l = cur;
        while (b[i]>0)
        {
            if (b[i]<a[cur]) {cout<<-1; return 0;}
            b[i]-=a[cur];
            if (b[i]==0)
            {
                ans+=max(i, cur) - min(i, l);
                cur++;
                break;
            }
            cur++;
        }
    }
    cout<<ans;
}

#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...)
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};

const int N=1e5+5;
int a[N],b[N],p[N];
void no(){
	cout<<"-1\n";
	exit(0);
}
int f[N];
int g(int l,int r){
	if(l>r)return 0;
	return f[r]-(l==0?0:f[l-1]);
}

int32_t main(){
	int n,l;
	cin>>n>>l;
	for(int i=1;i<=n;++i)cin>>a[i];
	for(int i=1;i<=n;++i)cin>>b[i];
	a[n+1]=b[n+1]=l+1;
	map<int,int> mp;
	mp[0]=0;
	for(int i=1;i<=n;++i){
		p[i]=-1;
		mp[a[i]-i]=i;
		if(mp.find(b[i]-i)!=mp.end()){
			p[i]=mp[b[i]-i];
		}
	}
	mp.clear();
	mp[a[n+1]-(n+1)]=n+1;
	for(int i=n;i>=1;--i){
		mp[a[i]-i]=i;
		if(p[i]==-1&&mp.find(b[i]-i)!=mp.end()){
			p[i]=mp[b[i]-i];
		}
		if(p[i]==-1)no();
	}
	p[0]=0;
	p[n+1]=n+1;
	for(int i=1;i<=n;++i){
		if(p[i]>p[i+1])no();
		f[p[i]]=1;
	}
	for(int i=1;i<=n+1;++i)f[i]+=f[i-1];
	int ans=0;
	for(int i=1;i<=n;++i){
		if(i==p[i])continue;
		if(i<p[i])ans+=g(i+1,p[i]);
		if(i>p[i])ans+=g(p[i],i-1);
	}
	cout<<ans<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")
#define REP(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
constexpr long long llinf = 1LL << 62;
using ll = long long;

namespace FastIO {
struct Strs {
  char strs[10000 * 4];
  constexpr Strs() : strs() {
    for (int i = 0; i < 10000; ++i) {
      int j = i;
      for (int t = 3; t >= 0; --t) {
        strs[i * 4 + t] = j % 10 + '0';
        j /= 10;
      }
    }
  }
} constexpr strs;
static constexpr size_t buf_size = 1 << 17;
char buf_in[buf_size], buf_out[buf_size];
size_t pt_in = 0, pt_out = 0, tail_in = 0;
inline size_t num_digits(long long x) {
  if (x >= (long long)1e9) {
    if (x >= (long long)1e18) return 19;
    if (x >= (long long)1e17) return 18;
    if (x >= (long long)1e16) return 17;
    if (x >= (long long)1e15) return 16;
    if (x >= (long long)1e14) return 15;
    if (x >= (long long)1e13) return 14;
    if (x >= (long long)1e12) return 13;
    if (x >= (long long)1e11) return 12;
    if (x >= (long long)1e10) return 11;
    return 10;
  } else {
    if (x >= (long long)1e8) return 9;
    if (x >= (long long)1e7) return 8;
    if (x >= (long long)1e6) return 7;
    if (x >= (long long)1e5) return 6;
    if (x >= (long long)1e4) return 5;
    if (x >= (long long)1e3) return 4;
    if (x >= (long long)1e2) return 3;
    if (x >= (long long)1e1) return 2;
    return 1;
  }
}
inline void load() {
  memcpy(buf_in, buf_in + pt_in, tail_in - pt_in);
  size_t width = tail_in - pt_in;
  tail_in = width + fread(buf_in + width, 1, buf_size - width, stdin);
  pt_in = 0;
}
inline void flush() {
  fwrite(buf_out, 1, pt_out, stdout);
  pt_out = 0;
}
inline void scan(char& c) { c = buf_in[pt_in++]; }
template <class T>
inline void scan(T& x) {
  if (pt_in + 32 > tail_in) load();
  char c;
  bool minus = 0;
  x = 0;
  scan(c);
  while (c >= '0') {
    x = x * 10 + (c & 15);
    scan(c);
  }
  if (minus) x = -x;
}
inline void print(char c) { buf_out[pt_out++] = c; }
template <class T>
inline void print(T x) {
  if (pt_out > buf_size - 32) flush();
  if (x < 0) {
    print('-');
    x = -x;
  }
  size_t digits = num_digits(x);
  int i;
  for (i = pt_out + digits - 4; i > (int)pt_out; i -= 4) {
    memcpy(buf_out + i, strs.strs + (x % 10000) * 4, 4);
    x /= 10000;
  }
  memcpy(buf_out + pt_out, strs.strs + x * 4 + (pt_out - i), 4 + i - pt_out);
  pt_out += digits;
}
inline void print(const char* s) {
  if (pt_out > buf_size - 32) flush();
  for (int i = 0; s[i] != 0; ++i) print(s[i]);
}
template <class T>
inline void println(T x) {
  print(x);
  print('\n');
}
struct SetUp {
  SetUp() { load(); }
  ~SetUp() { flush(); }
} setup;
}  // namespace FastIO

using FastIO::print;
using FastIO::println;
using FastIO::scan;

constexpr int mx = 200001;

int main() {
  int N, M;
  scan(N);
  scan(M);
  int H[mx], W[mx];
  REP(i, N) scan(H[i]);
  REP(i, M) scan(W[i]);
  sort(H, H + N);
  sort(W, W + M);
  ll left[N + 1], right[N + 1];
  left[0] = right[N] = 0;
  for (int i = 2; i <= N; i += 2) left[i] = left[i - 2] + H[i - 1] - H[i - 2];
  for (int i = N - 2; i >= 0; i -= 2) right[i] = right[i + 2] + H[i + 1] - H[i];
  int p = 0;
  ll ans = llinf;
  REP(i, M) {
    while (p < N && H[p] <= W[i]) p++;
    if (p % 2 == 0) {
      ans = min(ans, left[p] + right[p + 1] + H[p] - W[i]);
    } else {
      ans = min(ans, left[p - 1] + right[p] + W[i] - H[p - 1]);
    }
  }
  println(ans);
  return 0;
}

#include <bits/stdc++.h>
#include <vector>
using namespace std;

long long mypow(long a, long b) {
    long long powed = 1;
    if (b == 0) {
        return 1;
    } else {
        for (long i=0; i<b; i++) {
            powed = powed * a;
        }
    return powed;
    }
}

int main() {
    long long N;
    cin >> N;

    // bの最大値を求める
    long long bmax = 0;
    while (true) {
        if (mypow(2, bmax) <= N) {
            bmax = bmax;
        } else {
            break;
        }
        bmax += 1;
    }

    long long apbpc_min = 9223372036854775807;
    // bが大きい方から順番に最少となるa,b,cを試す
    for (long long b=bmax; b >= 0; b--) {
        // aの最大値を求める
        long long amax = floorl(N / mypow(2, b));
        long long apbpc_before;
        long long c = N - amax * mypow(2, b);
        long long apbpc = amax + b + c;
        if (apbpc_min > apbpc) {
            apbpc_min = apbpc;
        }
    }
    cout << apbpc_min << endl;

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pt;
typedef pair<ll,ll> pll;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_set tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update>

#define vint vector<int>
#define vll vector<long long>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define F(i,n) for(int i = 0;i<n;i++)
#define Fr(i,l,r) for(int i = l;i <= r;i++)
#define rF(i,n) for(int i = n-1;i>=0;i--)
#define Max 1000001
#define intinf 2147483647
#define longlonginf 9223372036854775807
#define MOD 998244353
#define MOD2 1000000007
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(arr) arr.begin(),arr.end()
//#define sort(vec) sort(vec.begin(),vec.end())
//#define reverse(vec) reverse(vec.begin(),vec.end())

ll Lpow(ll a,ll b)
{
    ll ans = 1;
    while(b > 0)
    {
        if(b%2)
            ans = (ans*a);
        a = (a*a);
        b = b/2;
    }
    return ans;
}

ll Lpow(ll a,ll b,ll M)
{
	ll ans = 1;
	while(b > 0)
	{
		if(b%2)
			ans = (ans*a)%M;
		a = (a*a)%M;
		b = b/2;
	}
	return ans;
}

ll x,y;
ll ans;
map<ll,ll> mape;

void sch(ll y,ll turns)
{
    ans = min(ans,abs(y - x) + turns);
    if(mape[y] <= turns && mape[y] != 0)
        return;
    else
    {
        mape[y] = turns;
        if(y%2)
        {
            sch(y + 1,turns + 1);
            sch(y - 1,turns + 1);
        }
        else
            sch(y/2,turns + 1);
    }
}

int main()
{
    fastio;

    ans = longlonginf;
    cin >> x >> y;

    sch(y,0);

    cout << ans << endl;

	return 0;
}

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

typedef long long int ll;
#define int ll
#define fast(); ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tests() int t; cin>>t; while(t--)
#define endl '\n'
#define sz(x) ll((x).size())
#define F first
#define S second
#define mp make_pair
#define vi vector <ll>
#define pii pair<ll, ll>
#define pdi pair<double, ll>
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define all(x) x.begin(),x.end()
#define f(i,n) for(ll i=0;i<n;i++)

#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbgv(x) { cout<< #x << ": "; for(auto i : x) cout << i << ' '; cout << '\n'; }

int inf = 1e18 + 100;
int mod = 1e9 + 7;
double pi = 3.1415926;

int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); }
int fpow(int a, int b, int _mod = mod) { if (b == 0)return 1; int t = (fpow(a, b / 2, _mod)); if (b % 2 == 0)return (t * t) % _mod; else return ((a) * (t * t)) % _mod; }

vi parent;
void make_set(int n) { parent.resize(n); f(i, n) parent[i] = i; }
int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); }
bool union_sets(int a, int b) { a = find_set(a); b = find_set(b); parent[b] = a; return a != b; }

signed main()
{
	int x, y, res = 0;
	cin >> x >> y;
	if (x >= y) {
		cout << x - y << endl;
		return 0;
	}
	res = y - x;
	int t = 1, k = 0, s = 1;
	while (x*s < 2*y) {
		k++;
		s *= 2;
		t = (k+1)*s;
		int d = abs(y - x*s);
		if (d > x * s) continue;//res = min(res, k + (d - t) + k + 1);
		else {
			int q = 0;
			int ss = s/2;
			while (d > 0) {
				q += d / s, d %= s;
				if (d > ss) d = min(ss * 2 - d, d - ss), q++;
				ss /= 2;
			}
			res = min(res, q + k);
		}
	}
	cout << res << endl;
}


#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define all(v) (v).begin(),(v).end()
#define all_rev(v) (v).rbegin(),(v).rend()
#define debug(x) cout << #x << ": " << x << '\n';
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
using P = pair<int,int>;
using PL = pair<ll, ll>;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  //cin.tie(0);ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15);
  ll x = 10000000000;

  int n;
  string t;
  cin >> n >> t;

  for (int i = 2; i < t.size(); i++) {
    if (t[i - 2] == '1') {
      if (t[i - 1] == '1') {
        if (t[i] != '0') {
          cout << 0 << endl;
          exit(0);
        }
      } else if (t[i - 1] == '0') {
        if (t[i] != '1') {
          cout << 0 << endl;
          exit(0);
        }
      }
    } else if (t[i - 2] == '0') {
      if (t[i - 1] == '1' && t[i] == '1') {
        continue;
      } else {
        cout << 0 << endl;
        exit(0);
      }
    }
  }

  if (t == "1") {
    cout << 2 * x << endl;
  }else if (t == "00") {
    cout << 0 << endl;
  } else if (t == "11" || t == "0" || t == "10") {
    cout << x << endl;
  } else {
    if (t[0] == '0') {
      // 0110110 -> 110110
      t = t.substr(1);
      x--;
    } else if (t[0] == '1' && t[1] == '0') {
      // 10110110 -> 110110
      t = t.substr(2);
      x--;
    }

    if (t.size() > 2) {
      x = (x - (t.size() / 3)) + 1;
      if (t.size() % 3) x--;
    }
    cout << x << endl;
  }

  return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cerr<<#x<<" = "<<x<<endl

li fastpow(li base,li exp,li M)
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    li n;

    cin>>n;

    li a[n];

    map<li,li> cnt;

    f(i,0,n-1)
    {
        cin>>a[i];

        cnt[a[i]]++;
    }

    map<li,li> cnt2;

    li ans=0;

    f(i,0,n-1)
    {
        cnt2[a[i]]++;

        ans+= n-i-1-(cnt[a[i]]-cnt2[a[i]]);
    }

    cout<<ans;
}

int main()
{
    //remove this in kickstart

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li t=1;

    // cin>>t;

    f(i,1,t)
    {
        // cout<<"Case #"<<i<<": ";

        solve();
    }

    return 0;
}


#include<bits/stdc++.h>
#define N 200006
#define LL __int128
#define int long long
using namespace std;

int T,t;
int X,Y,p,q;
int mod1,mod2;
int ai[12],bi[12];

inline int qr()
{
	char a=0;int w=1,x=0;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar();}
	return w*x;
}

LL exgcd(LL a,LL b,LL &x,LL &y)
{
	if(!b)
	{
		x=1,y=0;
		return a;
	}
	LL d=exgcd(b,a%b,y,x);
	y-=a/b*x;
	return d;
}

LL mul(LL a,LL b,LL mod)
{
	LL ans=0;
	while(b)
	{
		if(b&1)
			ans=(ans+a)%mod;
		a=(a+a)%mod;
		b>>=1;
	}
	return ans;
}

LL excrt()
{
    LL x,y;
    LL M=bi[1],ans=ai[1];
    for(int i=2;i<=2;i++)
    {
        LL a=M,b=bi[i],c=(ai[i]-ans%b+b)%b;
        LL gcd=exgcd(a,b,x,y),bg=b/gcd;
        if(c%gcd!=0) return -1;
        x=mul(x,c/gcd,bg);
        ans+=x*M;
        M*=bg;
        ans=(ans%M+M)%M;
    }
    return (ans%M+M)%M;
}

signed main()
{
	T=qr();
	while(T--)
	{
		X=qr();
		Y=qr();
		p=qr();
		q=qr();
		mod1=(X+Y)<<1;
		mod2=(p+q);
		LL ans=2e18;
		int opl=0;
		for(register int i=0;i<Y;i++)
		{
			for(register int j=p;j<p+q;j++)
			{
				bi[1]=mod1;
				bi[2]=mod2;
				ai[1]=i+X;
				ai[2]=j;
				LL ans1=excrt();
				if(ans1==-1)
					continue;
				opl=1;
				ans=min(ans1,ans);
			}
		}
		if(opl)
			cout<<(long long)ans<<endl;
		else
			cout<<"infinity"<<endl;
	}
	return 0;
}

#include<bits/stdc++.h>
#define rep(i, n) for (Int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(Int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(Int i=a;i<=Int(b);i++)
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);
//#include <atcoder/all>
//using namespace atcoder;
typedef long long Int;
const long long INF = 1ll << 60;
using namespace std;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  __MAGIC__
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = -1000000;
  ans = max(ans,a-c);
  ans = max(ans,a-d);
  ans = max(ans,b-c);
  ans = max(ans,b-d);

  cout << ans << endl;
//  cout << (ans ? "Yes" : "No") << endl;

  return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define endl "\n"
#define int long long int
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef pair<int, int> pii;
typedef vector<int> vi;

string to_string(string s)      {    return '"' + s + '"';   }
string to_string(const char* s) {   return to_string((string) s);   }
string to_string(bool b)        {   return (b ? "true" : "false");  }

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int n,m,k,i,j,mod;
vector<int> a,b,p;

void solvetestcase(){
  cin>>n;
  a.resize(n);
  b.resize(n);
  p.resize(n);
  for(auto &x:a)
    cin>>x;
  for(auto &x:b)
    cin>>x;
  for(auto &x:p)
  {
    cin>>x;
    x--;
  }
  for(int i=0;i<n;++i)
  {
    if(a[i]>b[p[i]]||i==p[i])
      continue;
    cout<<-1<<endl;
    return;
  }

  vi itr(n);
  iota(itr.begin(),itr.end(),0);
  sort(itr.begin(),itr.end(),[&](const int &x,const int &y){
    return a[x]>a[y];
  });
  debug(itr);
  vector<pii> ans;
  for(auto u:itr)
  {
    while(p[u]!=u)
    {
      const int v=p[u];
      assert(a[u]>b[p[u]]);
      assert(a[v]>b[p[v]]);
      ans.push_back({u,v});
      swap(p[u],p[v]);
    }
  }

  cout<<ans.size()<<endl;
  for(auto x:ans)
    cout<<x.X+1<<" "<<x.Y+1<<endl;
}

int32_t main(void) {
  FASTIO;
  int testcases=1;
  // cin>>testcases;
  for(int tc=1;tc<=testcases;++tc){
    solvetestcase();
  }
  return 0;
}

#include <cstring>
#include <iostream>
using namespace std;

typedef long long ll;

int net[1000001]; //指向下一结点的指针
int vis[1000001];  //对每个结点进行不同的标记
int ans, n, ringID, p;
void search()
{
    for (int i = 1; i <= n; ++i)
    {
        if (vis[i]) continue;
        p = i;
        ++ringID;           //对每一种环进行一种不同的标记，新的起点必须更换新的染色
        while (vis[p] == 0) //当前结点未被染色
        {
            vis[p] = ringID;      //染色
            p = net[p];          //指向下一个点
            if (vis[p] == ringID) //下一个点的颜色和当前染色相同,则说明存在一个环
                ++ans;
        }
    }
}

int qmi(int a, int k, int p)
{
    int res = 1;
    while (k)
    {
        if (k & 1)
            res = (ll)res * a % p;
        k >>= 1;
        a = (ll)a * a % p;
    }
    return res;
}

int main()
{
    cin >> n;
    ans = 0;
    ringID = 1;
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; ++i)
    {
        scanf("%d", &net[i]);
        if (net[i] == i)
        {
            vis[i] = ringID++; //先对自环进行预处理
            ans++;
        }
    }
    search();
    cout << qmi(2, ans, 998244353) - 1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll l, ans =0;
    cin >> l;
    ll last = 1;
    for(int i = 11; i > 0; i--) {
        ans = (last*(l - i))/(12-i);
        last = ans;
    }
    cout << ans;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using vi  = vector<int64_t>;
using vvi = vector<vi>;
using vc  = vector<char>;
using vvc = vector<vc>;
using vd  = vector<long double>;
using vvd = vector<vd>;
using pii = pair<int64_t, int64_t>;
using vp  = vector<pii>;
using vvp = vector<vp>;
int64_t INF = 1e18;
int64_t mod = 1e9 + 7;

int main() {
  int64_t l;
  cin >> l;

  int64_t half;
  vi pre_ans(210, 0);
  for (int i = 2; i <= 190; i++) {
    for (int j = 2; j <= 190; j++) {
      for (int k = 2; k <= 190; k++) {
        half = i + j + k;
        if (half > l - 6) continue;

        pre_ans[half] += (i-1) * (j-1) * (k-1);
      }
    }
  }
  int64_t ans = 0;
  for (int i=6; i <= l-6;i++) {
    ans += pre_ans[i] * pre_ans[l-i];
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr ll INF = 1LL << 30;
constexpr ll mod = 100000; //(ll)1e9 + 7;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
inline void init() {
    cin.tie(nullptr); cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}

int dx[] = { 0,1,1 ,0 };
int dy[] = { 0,0, 1,1 };

int main() {
    init();

    int H, W; cin >> H >> W;
    vector<string>vec(H);
    vector<vector<int>>cnt(H + 1, vector<int>(W + 1, 0));
    rep(i, 0, H)cin >> vec[i];
    int ans = 0;
    rep(i, 0, H) {
        rep(j, 0, W) {
            if (vec[i][j] == '#') {
                rep(k, 0, 4)cnt[i + dy[k]][j + dx[k]]++;
            }
        }
    }
    rep(i, 0, H + 1)rep(j, 0, W + 1)if (cnt[i][j] % 2 == 1)ans++;
    cout << ans << "\n";

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int h,w,i,j,black,white,sum;
    cin>>h>>w;
    char ar[h][w];
    string str;
    for (i=0;i<h;i++)
    {
        cin>>str;
        for(j=0;j<w;j++)
            ar[i][j]=str[j];
    }
    sum=0;
    for (i=0;i<h-1;i++)
    {
        for (j=0;j<w-1;j++)
        {
            white=black=0;
            if (ar[i][j]=='#')
                black++;
            else white++;
            if (ar[i][j+1]=='#')
                black++;
            else white++;
            if (ar[i+1][j]=='#')
                black++;
            else white++;
            if (ar[i+1][j+1]=='#')
                black++;
            else white++;
            if ((black==3 && white==1) || (white==3 && black==1))
                sum++;
        }
    }
    cout<<sum;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define rep(i,st,n) for(int i=st;i<n;i++)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n)
#define var(n) int n; scn(n)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define pb(n) push_back(n)
#define pii  pair<int,int>
const int N=3e3+6;
const ll M = 998244353;

ll dp[N][N];
// dp[i][j] is the number of ways with i
// elements and j sum.
int main()
{
	int n,k;
	cin>>n>>k;
	dp[0][0] = 1;
	for(int i = 1;i<=n;i++)
	{
		for(int sum = 1;sum<=i;sum++)
		{
			ll req = sum;
			while(req<=i)
			{
				dp[i][sum] += dp[i-1][req-1];
				if(dp[i][sum]>=M)
					dp[i][sum]-=M;
				req*=2;
			}
		}
	}

	lpri(dp[n][k]);
}

#include<bits/stdc++.h>
#define PI 3.141592653589793238462
#define eps 1e-10
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdd;
ll d[3005][3005],mod=998244353;
ll dfs(ll n,ll k){
    if(n<k) return 0;
    if(k==0) return !n;
    if(d[n][k]!=-1) return d[n][k];
    d[n][k]=(dfs(n-1,k-1)+dfs(n,k<<1))%mod;
    return d[n][k]%mod;
}
int main(){
    memset(d,-1,sizeof(d));
    ll n,k;cin>>n>>k;dfs(n,k);
    cout<<dfs(n,k)%mod<<endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main()
{
  ll n;
  cin >> n;

  vector<int> b;
  int k = 1;
  ll m = n;
  while(m > 0){
    if(m/10 != 0){
      k++;
    }
    b.emplace_back(m%10);
    m/=10;
  }

  if(n%3==0){
    cout << 0 << endl;
    return 0;
  }

  int ans = k+1;
  for(int i=1;i<(1<<k)-1;i++){
    ll sum = 0;
    int cnt = 0;
    for(int bit=0;bit<k;bit++){
      ll div = 1;

      if((i>>bit) & 1){
        // 削除する桁数を更新
        cnt++;
      }else{
        // sumに加算
        sum = sum*10 + b[bit];
      }

      div *= 10;

    }

    if(sum%3 == 0){
      ans = min(ans,cnt);
    }
  }

  if(ans == k+1) ans = -1;
  cout << ans << endl;

}


//tejustiwari
#include <bits/stdc++.h>
using namespace std;
#define ff                  first
#define ss                  second
#define pb                  push_back
#define mp                  make_pair
#define all(v)              v.begin(),v.end()
#define f(i,a,b,c)          for( i=a; i<b;i+=c)
#define rf(i,a,b,c)         for( i=b-1;i>=a;i-=c)
#define fo(i,n)             for( i=0; i < n ; i++)
#define rfo(i,n)            for( i=n-1; i >=0 ; i--)
#define mem(a,b)            memset(a, (b), sizeof(a))
#define alldec(v)           v.begin(),v.end(),greater<int>()
#define fio                 ios_base::sync_with_stdio(0); cin.tie(0);
#define debug1(x)           cout<<#x<<"="<<x<<endl;
#define debug2(x,y)         cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define debug3(x,y,z)       cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
#define debug4(x,y,z,w)     cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<" "<<#w <<"="<<w<<endl;
#define debugarray(arr,n)   for(int i=0;i<n;i++) {cout<<"i="<<i<<" arr[i]="<<arr[i]<<"\n";}
#define debugmatrix(a,n,m)  cout<<setw(5*m+8)<<"MATRIX\n\n";for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<setw(10)<<a[i][j];}cout<<"\n";}
#define file_io             freopen("Input_file_name.txt","r",stdin);freopen("Output_file_name.txt","w",stdout)
typedef long long int ll;   typedef vector<int> vi; typedef vector<ll> vll;   typedef pair<int,int>	pi;  typedef pair<ll,ll>	 pll;
const  ll M =1000000007;    const ll M1 = 998244353;      const double PI = 3.141592653589793;   vll primefactors, factors, fact;
bool isPowerTwo(ll x)       {return(x && !(x&(x-1)));}
ll   power(ll a, ll b)      {ll r=1;while(b){if(b&1)r=(r*a);a=(a*a);b>>=1;}return r;}
ll   powerM(ll a,ll b)      {ll r=1;while(b){if(b&1)r=(r*a)%M;a=(a*a)%M;b>>=1;}return r;}
void getFactorial(ll n)     {fact.pb(1);for(ll i=1;i<=n;i++)fact.pb((i*1ll*fact[i-1])%M);}
bool isPrime(ll n)          {if(n<2)return false;for(ll i=2;i*i<=n;i++)if(n%i==0)return false;return true;}
ll   modi(ll a)             {ll m=M,s=1,p=0; while(a>1){ll q=a/m,t=m;m=a%m;a=t;t=p;p=s-q*p;s=t;}return s>=0?s:s+M;}
void getFactors(ll n)       {factors.clear();for(ll i=1;i*i<=n;i++){if(n%i==0){factors.pb(i);if(n/i!=i)factors.pb(n/i);}}sort(all(factors));}
ll   add(ll a,ll b)         {return((a%M)+(b%M)+M)%M;}  ll sub(ll a,ll b){return((a%M)-(b%M)+M)%M;}  ll mul(ll a,ll b){return((a%M)*(b%M))%M;}
void getPrimeFactors(ll n)  {primefactors.clear();for(ll i=2;i*i<=n;i++){if(n%i==0){primefactors.pb(i);while(n%i==0)n=n/i;}}if(n!=1)primefactors.pb(n);}
bool isSubstring(string s1, string s2){ if (s1.find(s2) != string::npos) return true; else return false; }
ll   ncr(ll n, ll r)        {if(r==0)return 1;fact[0]=1;for(int i=1;i<=n;i++)fact[i]=fact[i-1]*i%M;return(fact[n]*modi(fact[r])%M*modi(fact[n-r])%M)%M;}

//--------------------------------------------------------------------Template Above--------------------------------------------------------------------

int main(){
  ll n,ans=0;
  cin>>n;
  ans=n+1;
  ans-=((ll)sqrtl(8*n+9)-1)/2;
  if(n==1)
    cout<<"1";
  else
    cout<<min(ans,n-1);
  return 0;
}

//------------------------------------------------------------------------------------------------------------------------------------------------------

#include <bits/stdc++.h>

using namespace std;

int main() {
  using ll = long long;
  ll n;
  cin >> n;
  ll l = 0, r = 2e9;
  while (r - l > 1) {
    ll m = (l + r) / 2;
    (m * (m + 1) / 2 <= n + 1 ? l : r) = m;
  }
  cout << n - l + 1 << endl;
  return 0;
}


#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long>
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int n, k, a[800][800];

int comp(int x) {
    int sum[n + 1][n + 1];
    rep(i, n + 1) sum[0][i] = 0;
    rep(i, n + 1) sum[i][0] = 0;
    rep(i, n) rep(j, n) sum[i + 1][j + 1] = sum[i][j + 1] + (a[i][j] >= x);
    rep(i, n - k + 1) {
        int tmp = 0;
        rep(j, k) tmp += sum[i + k][j] - sum[i][j];
        rep(j, n - k + 1) {
            tmp += sum[i + k][j + k] - sum[i][j + k] -
                sum[i + k][j] + sum[i][j];
            if (tmp < k * k / 2 + 1) return false;
        }
    }
    return true;
}

int main() {
    ci2(n, k);
    rep(i, n) rep(j, n) ci(a[i][j]);
    int l = 0, r = 1e9 + 1;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        ((comp(mid)) ? l : r) = mid;
    }
    co(l);
    return 0;
}

#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

ll A[810][810];
ll B[810][810];
ll S[810][810];
ll n,k;
bool f(ll x){
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(A[i][j]<=x) B[i][j]=1;
      else B[i][j]=0;
    }
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      S[i][j]=S[i][j-1]+B[i][j];
    }
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      S[i][j]+=S[i-1][j];
    }
  }
  bool b=false;
  for(int i=1;i+k-1<=n;i++){
    for(int j=1;j+k-1<=n;j++){
      if(S[i+k-1][j+k-1]-S[i+k-1][j-1]-S[i-1][j+k-1]+S[i-1][j-1]>=k*k-k*k/2){
        b=true;
        break;
      }
    }
    if(b) break;
  }

  if(b) return true;
  else return false;
}

int main(){
  cin>>n>>k;
  rep(i,n){
    rep(j,n) cin>>A[i+1][j+1];
  }

  ll ng=-1,ok=1e9+1;
  while(ok-ng>1){
    ll mid=(ng+ok)/2;
    if(f(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;

  f(4);

  return 0;
}


#include<bits/stdc++.h>
#define ll                  long long
#define dl                 long double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007LL
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  1000001LL
#define tmod             998244353LL
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll Powb(ll b,ll n,ll m);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
ll P[N+1];
void Sieve(int n=N);

int main()
{
fast;
ll q=1,t;
//cin >> q; t = q;
while(q--)
{
    ll i,j,n,m,k,l=0,r=0,a=0,b=0,c=0,d=0,e,g=1,p,u,v,w,x,y,z,flag=1;
    //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
    string s;
    cin >> s;
    n = s.size();
    for(i=0;i<n;i++) {
        if (i%2==0) {
            if (s[i] - 'A' < 26 and s[i] - 'A' >= 0)
            {
                flag = 0; break;
            }
        } else {
            if (s[i] - 'a' < 26 and s[i] - 'a' >= 0)
            {
                flag = 0; break;
            }
        }
    }

    if (flag) cout << "Yes";
    else cout << "No";
}
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}

ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid].F==ser)
    {
        return mid;
    }
    else if(PS[mid].F > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

void Sieve(int n)
{
    //memset(P,1,sizeof(P));
    P[0] = 0;
    P[1]= 0;
    for(int i=2;i<=n;i++) P[i] = 1;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i]==1)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=0;
            }
        }
    }

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,e,j;
 //e=1;;
 //while(e--)
 {

	 cin>>n;
	 long a[n],b[n],c[n],max,d;
	 for(i=0;i<n;i++)
	 cin>>a[i];
	 for(i=0;i<n;i++)
	 cin>>b[i];
	 c[0]=0;
	  max=a[0];
	 for(i=1;i<n;i++)
	 {
		 if(a[i]>max)
		 {
			 max=a[i];
			 c[i]=i;
		 }
		 else
		 c[i]=c[i-1];
	 }
	// for(i=0;i<n;i++)
	// cout<<c[i]<<" ";
	  long long dp[n];
	 dp[0]=a[0]*b[0];
	 for(i=1;i<n;i++)
	 {
		 dp[i]=dp[i-1];
		 long long t=a[c[i]]*b[i];
	     if(dp[i]<t)
		 dp[i]=t;

	 }
	 for(i=0;i<n;i++)
	 cout<<dp[i]<<"\n";
 }
}


#include <iterator>
#include <algorithm>
#include <list>
#include <deque>
#include <string>
#include <iostream>
using namespace std;
int main(){
    string str,str2;
    cin >> str;
    for (int i = str.size()-1;i >=0;i--){
        if (str[i] == '0') str.erase(i,1);
        else i = -1;
    }
    str2 =str;
    reverse(str.begin(),str.end());
    if (str == str2) cout << "Yes";
    else cout << "No";
}

#include <iostream>

using namespace std;

int main(){
  int n; cin >> n;
  if (n==0){
    cout << "Yes\n";
    return 0;
  }
  while (n%10==0) n/=10;
  int n_inv=0,t=n;
  while (t>0) {
    n_inv = (t%10)+(n_inv<<3)+(n_inv<<1);
    t/=10;
  }
  cout << (n==n_inv?"Yes\n":"No\n");
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rev_rep(i, a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int, int>
#define mod = 1e9 + 7

void __print(int x)
{
    cerr << x;
}
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

/* ************************************ CODE STATRTS HERE  *************************************/

void solve()
{
 int n , k ;
 cin>>n>>k;
 int sum = 0;
 rep(i,1,n)
 {
     rep(j,1,k)
     sum += i*100 + j;
 }
 cout<<sum<<endl;

}
int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vll vector<long long int>
#define vld vector<long double>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define mod2 998244353
#define ll long long int
#define ld long double
#define pi 3.141592653589793238
#define Endl endl
#define endl "\n"
const int N = 1e6 + 5;
const ll inf = 1e18;
// unordered_map<ll,ll> rk;
// bool cmp(ll a,ll b)
// {
//         return rk[a] < rk[b];
// }

void solve()
{
        ll a,b;
        cin>>a>>b;
        a=a+b;
        if(a>=15 && b>=8)
                cout<<"1";
        else if(a>=10 && b>=3)
                cout<<"2";
        else if(a>=3)
                cout<<"3";
        else
                cout<<"4";
}

void debug(ll tt) {}
 // [L,R] make a window which matches with prefix of s
signed main()
{
        FAST;
        int t = 1;
        //cin >> t;
        //fill();
        while(t--)
        {
                solve();
        }
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define rrep(i, n) for (ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X>
void print(X x)
{
    cout << x << endl;
}
void print(vl x)
{
    for (ll i : x)
    {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vector<vl> g(MAX_N * 10);
vl A, B;
ll masu[2001][2001];
vector<vector<PP>> V(26);
vl dis = vl(MAX_N * 10, INF);
void input()
{
    cin >> h >> w;
    rep(i, h)
    {
        cin >> S;
        rep(j, w)
        {
            if (S[j] == 'S')
            {
                e = i;
                f = j;
            }
            else if (S[j] == 'G')
            {
                r = i;
                t = j;
            }
            else if (S[j] == '#')
            {
                masu[i][j] = -1;
            }
            else if (S[j] != '.')
            {
                V[S[j] - 'a'].pb({i, j});
                masu[i][j] = S[j] - 'a' + 1;
            }
        }
    }
}
void solve()
{
    rep(i, h)
    {
        rep(j, w)
        {
            if (i > 0 && masu[i][j] != -1 && masu[i - 1][j] != -1)
                g[i * w + j].pb((i - 1) * w + j);
            if (i < h - 1 && masu[i][j] != -1 && masu[i + 1][j] != -1)
                g[i * w + j].pb((i + 1) * w + j);
            if (j > 0 && masu[i][j] != -1 && masu[i][j - 1] != -1)
                g[i * w + j].pb(i * w + j - 1);
            if (j < w - 1 && masu[i][j] != -1 && masu[i][j + 1] != -1)
                g[i * w + j].pb(i * w + j + 1);
        }
    }

    queue<ll> q;
    q.push(e * w + f);
    dis[e * w + f] = 0;
    while (!q.empty())
    {
        int v = q.front();
        q.pop();
        for (ll x : g[v])
        {
            if (dis[x] == INF)
            {
                dis[x] = dis[v] + 1;
                q.push(x);
            }
        }

        a = v / w;
        b = v % w;
        //print({v, a, b, masu[a][b]});
        if (masu[a][b] > 0)
        {
            p = masu[a][b] - 1;
            rep(i, V[p].size())
            {
                e = V[p][i].fi;
                f = V[p][i].se;
                masu[e][f] = 0;
                if (dis[e * w + f] == INF)
                {
                    dis[e * w + f] = dis[v] + 1;
                    q.push(e * w + f);
                }
            }
        }

        masu[a][b] = 0;
    }

    if (dis[r * w + t] < INF)
        print(dis[r * w + t]);
    else
        print(-1);
}
int main()
{
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while (codeforces--)
    {
        solve();
    }
}

#include<iostream>
#include<cstdio>
using namespace std;
const int N=5002020,INF=2e9;
int n,m,cnt,tot; char s[2020][2020];
int id[1000],v[N],dis[N],stk[N<<3]; bool vis[N];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
struct Edge{int to,next,w;}e[N<<4];
void add(int x,int y,int z){
	e[++tot].to=y; e[tot].next=v[x]; v[x]=tot; e[tot].w=z;
}
int get(int x,int y){return (x-1)*m+y;}
bool check(int x,int y){
	if(x<=n && y<=m && x>=1 && y>=1 && s[x][y]!='#')return 1;
	return 0;
}
void spfa(int x){
	for(int i=1;i<=cnt;i++)dis[i]=INF;
	dis[x]=0; int top; stk[top=1]=x;
	for(int i=1;i<=top;i++){
		int w=stk[i]; vis[w]=0;
		for(int p=v[w];p;p=e[p].next){
			int kp=e[p].to;
			if(dis[kp]>dis[w]+e[p].w){
				dis[kp]=dis[w]+e[p].w;
				if(!vis[kp])vis[stk[++top]=kp]=1;
			}
		}
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	cnt=get(n,m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='#')continue;
			for(int k=0;k<4;k++){
				int x=dx[k]+i,y=dy[k]+j;
				if(check(x,y))add(get(i,j),get(x,y),1),add(get(x,y),get(i,j),1);
			}
			if(s[i][j]>='a' && s[i][j]<='z'){
				if(!id[s[i][j]])id[s[i][j]]=++cnt;
				add(get(i,j),id[s[i][j]],1); add(id[s[i][j]],get(i,j),0);
			}
		}
	}
	int bg;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(s[i][j]=='S')bg=get(i,j);
	spfa(bg);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(s[i][j]=='G'){
				if(dis[get(i,j)]<INF)printf("%d\n",dis[get(i,j)]);
				else puts("-1");
			}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define w(t) ll t;cin>>t;while(t--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define precision cout<<fixed<<setprecision(10)
const ll mod=1e9+7;
using namespace std;
int main()
{
	IOS
	ll n,s=0,r;
	cin>>n;
  	fo(i,0,n)
    {
      ll a,b;
      cin>>a>>b;
      r=((b*(b+1))/2)-((a*(a-1))/2);
      s=s+r;
    }
  	cout<<s;
}

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

typedef long long ll;

int n;
ll x,a[55];
map<ll,ll> mem[55];

ll dfs(const int& i,const ll& v){
    if(i==0)return v==0;
    if(mem[i].find(v)!=mem[i].end())return mem[i][v];
    ll nv=v%a[i];
    mem[i][v]=dfs(i-1,nv);
    if(nv&&a[i]+v!=a[i+1]+nv)mem[i][v]+=dfs(i-1,a[i]-nv);
    return mem[i][v];
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>x;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    cout<<dfs(n,x%a[n])<<endl;

    return 0;
}


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

typedef long long ll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

const int MOD     = 1e9+7;
const int INF     = 0x3f3f3f3f;
const ll  LLINF   = 0x3f3f3f3f3f3f3f3f;
const int MAXN    = 100005;
const int MAXM    = 1000005;

ll a[MAXN], vis[MAXN];

int main(){

    ll A, B , C;
    cin >> A >> B >> C;
    int ans = 0;
    if(A<0 && B < 0 || A >= 0 && B >= 0) {
        if(A < B) ans = -1;
        else if(A == B) ans = 0;
        else ans = 1;
    }
    else if(A < 0 && B >= 0) {
        if(C%2 == 1) {
            ans = -1;
        } else {
            if(-1*A < B) ans = -1;
            else if(-1*A == B) ans = 0;
            else if(-1*A > B) ans = 1;
        }
    }
    else if(B<0 && A >= 0) {
        if(C%2 == 1) {
            ans = 1;
        } else {
            if(-1*B < A) ans = 1;
            else if(-1*B == A) ans = 0;
            else if(-1*B > A) ans = -1;
        }
    }
    if(ans == -1) cout << "<" << endl;
    else if(ans == 0) cout << "=" << endl;
    else cout << ">" << endl;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <stdlib.h>
#include <cstring>
#include <cmath>
#include <math.h>
#include <string>
typedef long long ll;
using namespace std;
#define inf 1e9
int a,b,c;
void solve(){
    cin >> a >> b >> c;
    a = 7-a;
    b = 7-b;
    c = 7-c;
    cout <<a+b+c;
}

int main(){
    solve();
    return 0;

}


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int main(void){
	int N, M;
	cin >> N >> M;
	vector<int> node;
	node.reserve(N);
	int input;
	for(int i=0; i<N; ++i){
		cin >> input;
		node.push_back(input);
	}
	for(int i=0; i<N; ++i){
		cin >> input;
		node.at(i)-=input;
	}

	long long int sum = 0;
	int c, d;
	for(int i=0; i<M; ++i){
		cin >> c >> d;
		--c, --d;
		if(node.at(c))
			sum+=node.at(c), node.at(c)=0;
		if(node.at(d))
			sum+=node.at(d), node.at(d)=0;
	}

	if(sum!=0){
		cout << "No" << endl;
		return 0;
	}
	for(int i=0; i<N; ++i){
		if(node.at(i)){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

//infの設定
#define INF32 2147483647
#define INF64 9223372036854775807
#define PRIME 1000000007
#define PI 3.141592653589793238
//repマクロ
#define rep(i,m,n) for (int i=(m); (i)<(int)(n); ++(i))
#define rrep(i,m,n) for (int i=(m); (i)>(int)(n); --(i))
//その他
#define eb emplace_back
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<long long,long long> Pl;
//#define int long long

//UnionFind木
struct UnionFind{
    vector<int> par;

    UnionFind(int n):par(n){
        for(int i=0;i<n;i++) par.at(i)=i;
    }

    int root(int x){
        if(par.at(x)==x) return x;
        return par.at(x)=root(par.at(x));
    }

    int merge(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return 0;
        par.at(rx)=ry;
        return 1;
    }

    bool isSame(int x,int y){
        int rx=root(x);
        int ry=root(y);
        return rx==ry;
    }
};

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> A(N),B(N);
    rep(i,0,N) cin>>A[i];
    rep(i,0,N) cin>>B[i];

    UnionFind UF(N);

    rep(i,0,M){
        int c,d;cin>>c>>d;
        UF.merge(c-1,d-1);
    }

    map<int,ll> ma;

    rep(i,0,N){
        int key=UF.root(i);
        if(ma.count(key)==0){
            ma.emplace(key,A[i]-B[i]);
        }else{
            ma.at(key)+=A[i]-B[i];
        }
    }

    for(auto k:ma){
        if(k.second!=0){
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;
    return 0;
}


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

#define mp          make_pair
#define pb          push_back
#define pf          push_front
#define ff          first
#define ss          second
#define all(x)      x.begin(),x.end()
#define rall(x)     x.rbegin(),x.rend()
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b))/gcd((a),(b))
#define endl        "\n"
#define pi          3.14159265358979323846
#define inf         1000000000
#define setbits(x)  __builtin_popcountll(x)
#define ordered_set    tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long ll;
typedef long double ld;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N = 1e5+50;
const ll mod = 1e9+7;
const ll INF = 1e18;

// int dx[9]={-1,-1,-1,0,1,1,1,0,0};
// int dy[9]={-1,0,1,1,1,0,-1,-1,0};
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};

bool compare(const pair<ll, ll>&i, const pair<ll, ll>&j)
{
    return i.second < j.second;
}

ll fact[N];
vector<bool> is_prime(100000,true);
vector<int>prime;

void pre()
{
    fact[0]=1;
    for(ll i=1;i<N;i++)
    {
        fact[i]=i*fact[i-1];
        fact[i]%=mod;
    }
}

ll modexp(ll x,ll n)
{
    ll r=1;
    while(n){
        if(n&1)
            r=(r*x)%mod;

        x=(x*x)%mod;
        n>>=1;
    }
    return r%mod;
}

ll modinv(ll x)
{
    return modexp(x,mod-2);
}

ll ncr(ll n,ll r)
{
    if(n<r)
        return 0;

    ll ans=(fact[n]%mod * modinv(fact[r])%mod * modinv(fact[n-r])%mod)%mod;
    return ans;
}

ll exp(ll x,ll n)
{
    ll r=1;
    while(n){
        if(n&1)
            r=(r*x);

        x=(x*x);
        n>>=1;
    }
    return r;
}

int n;
vector<int>C(N);
vector<int>adj[N];
bool vis[N];
map<int,int>m;
int ver;

vector<int>ans;

void dfs(int x){
    vis[x]=1;
    if(m[C[x]]==0)
        ans.pb(x);
    m[C[x]]++;
    for(auto ch:adj[x]){
        if(!vis[ch]){
            dfs(ch);
        }
    }
    m[C[x]]--;
}

void solve()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>C[i];
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(1);
    sort(ans.begin(),ans.end());
    for(auto x:ans)
        cout<<x<<endl;
    return ;
}

int32_t main()
{
    fio

    // #ifdef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif

    // pre();
    int t=1;
    // cin>>t;
    for(int i=0;i<t;i++)
    {
        solve();
    }
    return 0;
}

#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int MOD2 = 998'244'353;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}

std::set<int> dfs(int cur, int prv, std::vector<int> &C, std::set<int> &c, std::vector<std::vector<int>> &G){
    std::set<int> rt;
    if(c.find(C[cur]) == std::end(c)) rt.insert(cur);
    c.insert(C[cur]);
    for(auto v: G[cur]){
        if(v == prv) continue;
        std::set<int> b{dfs(v, cur, C, c, G)};
        if(b.size() > rt.size()) swap(b, rt);
        for(auto e: b){
            rt.insert(e);
        }
    }
    if(rt.find(cur) != std::end(rt)) c.erase(C[cur]);
    return rt;
}

int main(){
    int N; std::cin >> N;
    std::vector<int> C(N);
    for(auto &e: C) std::cin >> e;
    std::vector<std::vector<int>> G(N);
    {
        int A, B;
        for(int i{0}, i_len{N-1}; i < i_len; ++i){
            std::cin >> A >> B;
            G[--A].push_back(--B);
            G[B].push_back(A);
        }
    }
    std::set<int> c;
    std::set<int> ans{dfs(0, NIL, C, c, G)};
    for(auto e: ans){
        std::cout << e+1 << "\n";
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vii;
typedef vector<pii> vpii;
typedef unordered_map<int,int> umap;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define mp make_pairNa
#define popcount __builtin_popcount
#define case cout<<"Case "<<z-t<<": ";
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m,i,j,k;
    cin>>n>>m;
    pair<ll,ll> fnd[n];
    for(i=0;i<n;i++) cin>>fnd[i].fi>>fnd[i].se;
    sort(fnd,fnd+n);
    ll ans=m;
    for(i=0;i<n;i++){
        if(ans>=fnd[i].fi) ans+=fnd[i].se;
        else break;
    }
    cout<<ans<<endl;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0;i<(n);i++)
#define mod (1000000007)

int main()
{
	int N,W;
	cin >> N >> W;
	cout << (N / W) << endl;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
using ll = long long;

vector<string> s(800);

vector<vector<char>> a(20, vector<char>(20));

// 部分列は構成済みか
vector<bool> used(800, false);

int main() {
    int n, m;
    cin >> n >> m;
    rep(i,m) cin >> s[i];

    rep(i,n) {
        int w=0;
        rep(j, m) {
            if(w+s[j].size() < n && !used[j]) {
                for(int k=w; k < w+s[j].size(); k++) {
                    a[i][k] = s[j][k-w];
                }
                w += s[j].size();
                used[j] = true;
            }
            if(w == n) break;
        }
        while(w<n) {
            a[i][w] = '.';
            w++;
        }
    }

    rep(i,n) {
        rep(j,n) {
            cout << a[i][j];
        }
        cout << endl;
    }

}

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define ll long long
#define rep(i,n) for(int i = 0;i < (int)n;i ++)
using namespace std;

ll n,m;
vector<vector<ll>> ans(20,vector<ll>(20,-1));
vector<vector<ll>> a;
vector<tuple<ll,ll>> b;

void GETVALUE(){
  cin >> n >> m;
  rep(i,m){
    string s;
    cin >> s;
    a.push_back({});
    rep(j,(s.size())){
      a[i].push_back(s[j]-'A');
    }
    b.push_back(make_tuple((s.size()),i));
  }
  sort(b.begin(),b.end());
}
void PUTVALUE(){
  rep(i,n){
    rep(j,n){
      if(ans[i][j] == -1){
        cout << '.';
      }else{
        char l = 'A'+ans[i][j];
        cout << l;
      }
    }
    cout << endl;
  }
}
void MAKEANS(){
  m = b.size();
  ll I = 0;
  rep(i,n){
    ll p = 0;
    while(p + get<0>(b[I]) <= n){
      for(ll j:a[get<1>(b[I])]){
        ans[i][p] = j;
        p ++;
      }
      I ++;
      if(I >= m)break;
    }
    if(I >= m)break;
    if(p >= n-1)continue;
    rep(j,n-p){
      ans[i][p+j] = a[get<1>(b[I])][j];
    }
    I ++;
  }
}
void SORTANS(){
  m = b.size();
  vector<vector<ll>> END(64);
  vector<vector<ll>> STA(64);
  rep(i,m){
    ll x = a[i].size();
    STA[a[i][0]*8+a[i][1]].push_back(i);
    END[a[i][x-2]*8+a[i][x-1]].push_back(i);
  }
  rep(i,64){
    while((not END[i].empty()) and (not STA[i].empty())){
      ll p = END[i].back();
      ll q = STA[i].back();
      END[i].pop_back();
      STA[i].pop_back();
      for(ll j = (b.size())-1;j >= 0;j --){
        if(get<1>(b[j]) == p or get<1>(b[j]) == q){
          b.erase(b.begin()+j);
        }
      }
      ll s1 = a[p].size();
      ll s2 = a[q].size();
      rep(j,s2-2){
        a[p].push_back(a[q][j+2]);
      }
      b.insert(b.begin(),make_tuple(s1+s2-2,p));
    }
  }
}

int main(void){
  GETVALUE();
  rep(i,10)SORTANS();
  MAKEANS();
  PUTVALUE();
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

int main(){
    int a,b;
    cin>>a>>b;
    cout<<2*a+100-b<<endl;
    return 0;
}
/*

*/

#include <iostream>
using namespace std;
int main()
{
   int n,m;
   int c;
   cin>>m>>n;
    cout<<(( 2*m+100)-n);
}