#include <bits/stdc++.h>

using namespace std;
#define ll long long

int main()
{
    int i;
    ll n, s;
    cin >> n >> s;

    ll a[n];
    for (i = 0; i < n; i++)
        cin >> a[i];

    //sort(a, a + n);
    ll tot = 0;
    for (i = 0; i < n; i++)
        tot += a[i];

    ll dif = 0, cnd1, cnd2;
    if (n == 1) {
        cout << a[0] - 1;
    }
    else {
    for (i = 0; i < n; i++) {
        ll ans = 0;
        if (s < n)
            cout << a[i] << " ";
        else {

                dif = s - (tot - a[i]);
                cnd1 = dif - 1;
                cnd1 = max((ll)0, cnd1);
                dif = s - n;
                cnd2 = a[i] - (dif + 1);
                cnd2 = max((ll)0, cnd2);
                //cout << cnd1 << " " << cnd2 << endl;
                cout << cnd1 + cnd2 << " ";
        }
    }
    }
    printf("\n");

    return 0;
}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <iterator>
#include <vector>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
#define countBits(msk) __builtin_popcount(msk)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
typedef vector<int> vi;
typedef istringstream iss;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vii;
typedef pair<int,int> ii;
#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
const double EPS = 1e-7;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
int dcmp(double x, double y) {  return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
int N;
long long S;

long long arr[2*100000+1];
long long prefix_max[2*100000+1];
long long suffix_max[2*100000+1];
int main(){
	clr(prefix_max,0);
	clr(suffix_max,0);
	scanf("%I64%I64",&N,&S);
	lp(i,N){
		cin>>arr[i];
		if(i>0)prefix_max[i]+=arr[i]+prefix_max[i-1];
		else prefix_max[i] = arr[i];

	}
	for(int i=N-1;i>=0;i--){
		suffix_max[i] += arr[i];
		if(i+1<N)suffix_max[i]+=suffix_max[i+1];

	}
	int cnt = 0;
	long long mx = 0,can_remove=0;
	lp(i,N){
		cnt = 0;
		mx = 0;
		if(i>0)	mx +=prefix_max[i-1];
		if(i+1<N)mx+=suffix_max[i+1];

		lp1(k,arr[i]){
             if(mx+k>=S){
            	 can_remove = mx-(N-1);
            	 if(mx+k-can_remove<=S) continue;
             }

            cnt++;

		}
		printf("%I64",cnt);
	}

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <iterator>
#include <vector>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
#define countBits(msk) __builtin_popcount(msk)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
typedef vector<int> vi;
typedef istringstream iss;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vii;
typedef pair<int,int> ii;
#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
const double EPS = 1e-6;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
int dcmp(double x, double y) {  return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
LL arr[2*(100000+1)];
LL sum = 0;
LL N,A;
int main(){
	fast
	cin >> N >> A;
	lp(i,N){
		cin >> arr[i];
		sum += arr[i];
	}
	lp(i,N){
		LL mn = N-1;
		LL mx = sum-arr[i];
		LL x = A-mn;  //biggest value that can be put.
		if(x>arr[i]){
			mn += x-arr[i];
			x = arr[i];
		}
		LL can_add = mx-mn;
	LL poss =  arr[i]-min(x-1,can_add)-1;
	cout << max((LL)0,poss) << " ";

		}

	}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <iterator>
#include <vector>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
#define countBits(msk) __builtin_popcount(msk)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
typedef vector<int> vi;
typedef istringstream iss;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vii;
typedef pair<int,int> ii;
#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
const double EPS = 1e-7;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
int dcmp(double x, double y) {  return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
int N;
long long S;

long long arr[2*100000+1];
long long prefix_max[2*100000+1];
long long suffix_max[2*100000+1];
int main(){
	fast
	clr(prefix_max,0);
	clr(suffix_max,0);
	cin >> N >> S;
	lp(i,N){
		cin>>arr[i];
		if(i>0)prefix_max[i]+=arr[i]+prefix_max[i-1];
		else prefix_max[i] = arr[i];
	}
	for(int i=N-1;i>=0;i--){
		suffix_max[i] += arr[i];
		if(i-1>=0)suffix_max[i]+=suffix_max[i-1];
	}
	int cnt = 0;
	long long mx = 0;
	lp(i,N){
		cnt = 0;
		mx = 0;
		if(i>0)	mx += prefix_max[i-1];
			if(i+1<N)mx+=suffix_max[i+1];

		lp1(k,arr[i]){
	    if(S==mx+k){
	    	++cnt;
	    	continue;
	    }
	    else if(S<mx+k){
	    	long long rem = mx+k-S;
	    	long long poss = mx-(N-1);
	    	if(poss>=rem){
	    		cnt++;
	    	}

	    }

		}
		cout << arr[i]-cnt <<" ";
	}
}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <iterator>
#include <vector>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
#define countBits(msk) __builtin_popcount(msk)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
typedef vector<int> vi;
typedef istringstream iss;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vii;
typedef pair<int,int> ii;
#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
const double EPS = 1e-7;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
int dcmp(double x, double y) {  return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
int N;
long long S;

long long arr[2*100000+1];
long long prefix_max[2*100000+1];
long long suffix_max[2*100000+1];
int main(){
	clr(prefix_max,0);
	clr(suffix_max,0);
	scanf("%d%d",&N,&S);
	lp(i,N){
		scanf("%d",arr+i);
		if(i>0)prefix_max[i]+=arr[i]+prefix_max[i-1];
		else prefix_max[i] = arr[i];

	}
	for(int i=N-1;i>=0;i--){
		suffix_max[i] += arr[i];
		if(i+1<N)suffix_max[i]+=suffix_max[i+1];

	}
	int cnt = 0;
	long long mx = 0,can_remove=0;
	lp(i,N){
		cnt = 0;
		mx = 0;
		if(i>0)	mx +=prefix_max[i-1];
		if(i+1<N)mx+=suffix_max[i+1];

		lp1(k,arr[i]){
             if(mx+k>=S){
            	 can_remove = mx-(N-1);
            	 if(mx+k-can_remove<=S) continue;
             }

            cnt++;

		}
		printf("%d ",cnt);
	}

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <iterator>
#include <vector>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
#define countBits(msk) __builtin_popcount(msk)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
typedef vector<int> vi;
typedef istringstream iss;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vii;
typedef pair<int,int> ii;
#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
const double EPS = 1e-7;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
int dcmp(double x, double y) {  return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
int N;
long long S;

long long arr[2*100000+1];
long long prefix_max[2*100000+1];
long long suffix_max[2*100000+1];
int main(){
	clr(prefix_max,0);
	clr(suffix_max,0);
	scanf("%I64%I64",&N,&S);
	lp(i,N){
		cin>>arr[i];
		if(i>0)prefix_max[i]+=arr[i]+prefix_max[i-1];
		else prefix_max[i] = arr[i];

	}
	for(int i=N-1;i>=0;i--){
		suffix_max[i] += arr[i];
		if(i+1<N)suffix_max[i]+=suffix_max[i+1];

	}
	int cnt = 0;
	long long mx = 0,can_remove=0;
	lp(i,N){
		cnt = 0;
		mx = 0;
		if(i>0)	mx +=prefix_max[i-1];
		if(i+1<N)mx+=suffix_max[i+1];

		lp1(k,arr[i]){
             if(mx+k>=S){
            	 can_remove = mx-(N-1);
            	 if(mx+k-can_remove<=S) continue;
             }

            cnt++;

		}
		printf("%I64 ",cnt);
	}

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <iterator>
#include <vector>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
#define countBits(msk) __builtin_popcount(msk)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
typedef vector<int> vi;
typedef istringstream iss;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vii;
typedef pair<int,int> ii;
#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
const double EPS = 1e-7;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
int dcmp(double x, double y) {  return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
int N;
long long S;

long long arr[2*100000+1];
long long sum = 0;
int main(){

	scanf("%d%d",&N,&S);
	lp(i,N){
		scanf("%d",arr+i);
		sum += arr[i];
	}
	int cnt = 0;
	long long mx = 0,can_remove=0;
	lp(i,N){
		cnt = 0;

		lp1(k,arr[i]){
			mx = sum;
			 mx = mx-arr[i];
             if(mx+k>=S){
            	 can_remove = mx-(N-1);
            	 if(mx+k-can_remove<=S) continue;
             }

            cnt++;

		}
		printf("%d ",cnt);
	}

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <iterator>
#include <vector>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
#define countBits(msk) __builtin_popcount(msk)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
typedef vector<int> vi;
typedef istringstream iss;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vii;
typedef pair<int,int> ii;
#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
const double EPS = 1e-7;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
int dcmp(double x, double y) {  return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
int N;
long long S;

long long arr[2*100000+1];
long long prefix_max[2*100000+1];
long long suffix_max[2*100000+1];
int main(){
	fast
	clr(prefix_max,0);
	clr(suffix_max,0);
	cin >> N >> S;
	lp(i,N){
		cin>>arr[i];
		if(i>0)prefix_max[i]+=arr[i]+prefix_max[i-1];
		else prefix_max[i] = arr[i];

	}
	for(int i=N-1;i>=0;i--){
		suffix_max[i] += arr[i];
		if(i+1<N)suffix_max[i]+=suffix_max[i+1];

	}
	int cnt = 0;
	long long mx = 0,can_remove=0;
	lp(i,N){
		cnt = 0;
		mx = 0;
		if(i>0)	mx +=prefix_max[i-1];
		if(i+1<N)mx+=suffix_max[i+1];

		lp1(k,arr[i]){
             if(mx+k>=S){
            	 can_remove = mx-(N-1);
            	 if(mx+k-can_remove<=S) continue;
             }

            cnt++;

		}
		cout << cnt << " ";
	}

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <iterator>
#include <vector>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
#define countBits(msk) __builtin_popcount(msk)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
typedef vector<int> vi;
typedef istringstream iss;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vii;
typedef pair<int,int> ii;
#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
const double EPS = 1e-7;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
int dcmp(double x, double y) {  return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
int N;
long long S;

long long arr[2*100000+1];
long long prefix_max[2*100000+1];
long long suffix_max[2*100000+1];
int main(){
	fast
	clr(prefix_max,0);
	clr(suffix_max,0);
	cin >> N >> S;
	lp(i,N){
		cin>>arr[i];
		if(i>0)prefix_max[i]+=arr[i]+prefix_max[i-1];
		else prefix_max[i] = arr[i];

	}
	for(int i=N-1;i>=0;i--){
		suffix_max[i] += arr[i];
		if(i+1<N)suffix_max[i]+=suffix_max[i+1];

	}
	int cnt = 0;
	long long mx = 0;
	lp(i,N){
		cnt = 0;
		mx = 0;
		if(i>0)	mx += prefix_max[i-1];
		if(i+1<N)mx+=suffix_max[i+1];

		lp1(k,arr[i]){
			if(i>0) mx += prefix_max[i-1];
			if(i+1<N) mx+= suffix_max[i+1];
             if(mx+k>=S){
            	 long long can_remove = mx-(N-1);
            	 if(mx+k-can_remove<=S) continue;
             }

            cnt++;

		}
		cout << cnt << " ";
	}

}


#include<iostream>
#include<cstring>
#include <cstdio>
using namespace std;
#define len 200000
int main()
{
    int n,A;
    int s[len+5];
    while(scanf("%d%d",&n,&A)!=EOF)
    {
        for(int i=1; i<=n; ++i)
            cin>>s[i];
        if(n==1) cout<<s[1]-1<<endl;
        else{
            for(int i=1; i<=n; ++i)
            {
                int sum=A;
                for(int j=1; j<=n; ++j)
                {
                    if(i!=j)
                        sum=sum-s[j];
                }
                if(sum>0)
                {
                    sum=sum-1;
                    if((s[i]-A+n-1)>0)
                        sum=sum+s[i]-A+n-1;
                    cout<<sum;

                }
                else if(sum==0)
                {
                    if((s[i]-A+n-1)>0)
                        sum=sum+s[i]-A+n-1;
                    cout<<sum;
                }
                else if(sum<0)
                {
                    sum=A-n+1;
                    if((s[i]-sum)>0) cout<<s[i]-sum;
                    else cout<<"0";

                }
                if(i!=n)cout<<" ";
                else cout<<endl;
            }
        }
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include <cstdio>
using namespace std;
#define len 200000
int main()
{
    int n,A;
    int s[len+5];
    while(scanf("%d%d",&n,&A)!=EOF)
    {
        for(int i=1; i<=n; ++i)
            cin>>s[i];
        if(n==1) cout<<s[1]-1<<endl;
        else{
            for(int i=1; i<=n; ++i)
            {
                int sum=A;
                for(int j=1; j<=n; ++j)
                {
                    if(i!=j)
                        sum=sum-s[j];
                }
                if(sum>0)
                {
                    sum=sum-1;
                    if((s[i]-A+n-1)>0)
                        sum=sum+s[i]-A+n-1;
                    cout<<sum;

                }
                else if(sum==0)
                {
                    if((s[i]-A+n-1)>0)
                        sum=sum+s[i]-A+n-1;
                    cout<<sum;
                }
                else if(sum<0)
                {
                    sum=A-n+1;
                cout<<s[i]-sum;
                }
                if(i!=n)cout<<" ";
                else cout<<endl;
            }
        }
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include <cstdio>
using namespace std;
#define len1 200000
int main()
{
    long long n,A;
    long long s[len1+5];
    while(scanf("%I64d%I64d",&n,&A)!=EOF)
    {
        long long len=0;
        for(int i=1; i<=n; ++i)
            {
                scanf("%I64d",&s[i]);
                len=len+s[i];
            }
        if(n==1) printf("%I64d\n",s[1]-1);
        else{
            for(int i=1; i<=n; ++i)
            {
                long long sum=A;
                sum=sum-len+s[i];
                if(sum>0)
                {
                    sum=sum-1;
                    if((s[i]-A+n-1)>0)
                        sum=sum+s[i]-A+n-1;
                    printf("%I64d",sum);

                }
                else if(sum==0)
                {
                    if((s[i]-A+n-1)>0)
                        sum=sum+s[i]-A+n-1;
                        printf("%I64d",sum);
                }
                else if(sum<0)
                {
                    sum=A-n+1;
                    if((s[i]-sum)>0) printf("%I64d",s[i]-sum);
                    else printf("0");

                }
                if(i!=n)printf(" ");
                else printf("\n");
            }
        }
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include <cstdio>
using namespace std;
#define len1 200000
int main()
{
    int n,A;
    int s[len1+5];
    while(scanf("%d%d",&n,&A)!=EOF)
    {
        int len=0;
        for(int i=1; i<=n; ++i)
            {
                scanf("%d",&s[i]);
                len=len+s[i];
            }
        if(n==1) printf("%d\n",s[1]-1);
        else{
            for(int i=1; i<=n; ++i)
            {
                int sum=A;
                sum=sum-len+s[i];
                if(sum>0)
                {
                    sum=sum-1;
                    if((s[i]-A+n-1)>0)
                        sum=sum+s[i]-A+n-1;
                    printf("%d",sum);

                }
                else if(sum==0)
                {
                    if((s[i]-A+n-1)>0)
                        sum=sum+s[i]-A+n-1;
                        printf("%d",sum);
                }
                else if(sum<0)
                {
                    sum=A-n+1;
                    if((s[i]-sum)>0) printf("%d",s[i]-sum);
                    else printf("0");

                }
                if(i!=n)printf(" ");
                else printf("\n");
            }
        }
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include <cstdio>
using namespace std;
#define len 200000
int main()
{
    int n,A;
    int s[len+5];
    while(scanf("%d%d",&n,&A)!=EOF)
    {
        for(int i=1; i<=n; ++i)
            scanf("%d",&s[i]);
            //cin>>s[i];
        if(n==1) printf("%d\n",s[1]-1);//cout<<s[1]-1<<endl;
        else{
            for(int i=1; i<=n; ++i)
            {
                int sum=A;
                for(int j=1; j<=n; ++j)
                {
                    if(i!=j)
                        sum=sum-s[j];
                }
                if(sum>0)
                {
                    sum=sum-1;
                    if((s[i]-A+n-1)>0)
                        sum=sum+s[i]-A+n-1;
                    printf("%d",sum);
                    //cout<<sum;

                }
                else if(sum==0)
                {
                    if((s[i]-A+n-1)>0)
                        sum=sum+s[i]-A+n-1;
                        printf("%d",sum);
                    //cout<<sum;
                }
                else if(sum<0)
                {
                    sum=A-n+1;
                    if((s[i]-sum)>0) printf("%d",s[i]-sum); //cout<<s[i]-sum;
                    else printf("0"); //cout<<"0";

                }
                if(i!=n)printf(" "); //cout<<" ";
                else printf("\n"); //cout<<endl;
            }
        }
    }
    return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advises/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(a,n) for(long int i = a; i < n; ++i)
#define FLL(a,n) for(long long int i = a; i < n; ++i)
#define FD(i,a,n) for(int i=(a);i>=(n);--i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<endl
#define DO(x, y) cout<<x<<" "<<y<<endl
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<endl
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl

#define fr first
#define se second

#define debug(i,sz,x) F(i,0,sz){cout<<x[i]<<" ";}cout<<endl

ill ABS(ill a) { if ( a < 0 ) return (-a); return a; }

/*
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

//CODE STARTS HERE

int a[2000001];

int main()
{
	int n, A;
	ill sm=0;
	DI(n, A);
	F(i, 0, n)
	{
		SI a[i];
		sm+=a[i];
	}
	F(i, 0, n)
		cout<<a[i] - (min(a[i], A-(n-1)) - max(1LL, A - (sm - a[i]))  + 1)<<" ";
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advises/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(a,n) for(long int i = a; i < n; ++i)
#define FLL(a,n) for(long long int i = a; i < n; ++i)
#define FD(i,a,n) for(int i=(a);i>=(n);--i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<endl
#define DO(x, y) cout<<x<<" "<<y<<endl
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<endl
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl

#define fr first
#define se second

#define debug(i,sz,x) F(i,0,sz){cout<<x[i]<<" ";}cout<<endl

ill ABS(ill a) { if ( a < 0 ) return (-a); return a; }

/*
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

//CODE STARTS HERE

int d[2000001], mins[2000001];

int main()
{
	int n, a;
	ill sm=0;
	DI(n, a);
	F(i, 0, n)
	{
		SI d[i];
		sm+=d[i];
	}
	if(n==1)
		cout<<d[0]-1<<endl;
	else
	{
		F(i, 0, n)
		{
			int minimum_value = 0;
			if(sm == a)
				minimum_value = d[i];
			else if (a < d[i])
				minimum_value = d[i] - a;
			if(d[i] == a)
				cout<<1+minimum_value<<" ";
			else if (d[i] > a)
				cout<<(d[i] - a)+minimum_value<<" ";
			else
				cout<< minimum_value <<" ";
		}
	}
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advises/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(a,n) for(long int i = a; i < n; ++i)
#define FLL(a,n) for(long long int i = a; i < n; ++i)
#define FD(i,a,n) for(int i=(a);i>=(n);--i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<endl
#define DO(x, y) cout<<x<<" "<<y<<endl
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<endl
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl

#define fr first
#define se second

#define debug(i,sz,x) F(i,0,sz){cout<<x[i]<<" ";}cout<<endl

ill ABS(ill a) { if ( a < 0 ) return (-a); return a; }

/*
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

//CODE STARTS HERE

int a[2000001];

int main()
{
	int n, A;
	ill sm=0;
	DI(n, A);
	F(i, 0, n)
	{
		SI a[i];
		sm+=a[i];
	}
	F(i, 0, n)
		cout<<a[i] - (min(0 + a[i], A-(n-1)) - max(1LL, A - (sm - a[i]))  + 1)<<" ";
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advises/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(a,n) for(long int i = a; i < n; ++i)
#define FLL(a,n) for(long long int i = a; i < n; ++i)
#define FD(i,a,n) for(int i=(a);i>=(n);--i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<endl
#define DO(x, y) cout<<x<<" "<<y<<endl
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<endl
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl

#define fr first
#define se second

#define debug(i,sz,x) F(i,0,sz){cout<<x[i]<<" ";}cout<<endl

ill ABS(ill a) { if ( a < 0 ) return (-a); return a; }

/*
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

//CODE STARTS HERE

ill a[2000001];

int main()
{
	ill n, A;
	ill sm=0;
	DI(n, A);
	F(i, 0, n)
	{
		SI a[i];
		sm+=a[i];
	}
	F(i, 0, n)
		cout<<a[i] - (min(0LL + a[i], A-(n-1)) - max(1LL, A - (sm - a[i]))  + 1LL)<<" ";
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advises/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(a,n) for(long int i = a; i < n; ++i)
#define FLL(a,n) for(long long int i = a; i < n; ++i)
#define FD(i,a,n) for(int i=(a);i>=(n);--i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<endl
#define DO(x, y) cout<<x<<" "<<y<<endl
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<endl
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl

#define fr first
#define se second

#define debug(i,sz,x) F(i,0,sz){cout<<x[i]<<" ";}cout<<endl

ill ABS(ill a) { if ( a < 0 ) return (-a); return a; }

/*
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

//CODE STARTS HERE

int d[2000001], mins[2000001];

int main()
{
	int n, a;
	ill sm=0;
	DI(n, a);
	F(i, 0, n)
	{
		SI d[i];
		sm+=d[i];
	}
	if(n==1)
		cout<<d[0]-1<<endl;
	else
	{
		F(i, 0, n)
		{
			int minimum_value = 0;
			if(sm == a)
				minimum_value = d[i]-1;
			else if (a < d[i])
				minimum_value = d[i] - a;
			if(d[i] == a)
				cout<<1+minimum_value<<" ";
			else if (d[i] > a)
				cout<<(d[i] - a)+minimum_value<<" ";
			else
				cout<< minimum_value <<" ";
		}
	}
	return 0;
}


/*

   			 ||Sri:||

                      __|
 ______________|_________________________
      |    |   ___|    |    |    ___|      |      |    |___
 /\  /\    |   |___    |    |   |___|      |      |    |___|
/  \/  \   |   ___|    |    |         |_/    |___|    |___

I am a beginner. Feel free to send tutorials/help to srinivasan1995@gmail.com.

Codeforces, SPOJ handle: desikachariar.
Hackerrank, Codechef handle: Prof_Calculus.

Advises/Help are welcome. You will definitely get a thanks in return. Comments to be avoided.

College: International Institute of Information Technology, Bangalore.
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <complex>
#include <stdlib.h>

using namespace std;

#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double

#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())

#define F(i,a,n) for(int i=(a); i<(n); ++i)
#define FL(a,n) for(long int i = a; i < n; ++i)
#define FLL(a,n) for(long long int i = a; i < n; ++i)
#define FD(i,a,n) for(int i=(a);i>=(n);--i)

#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)

#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z

#define SO(x) cout<<x<<endl
#define DO(x, y) cout<<x<<" "<<y<<endl
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<<endl
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl

#define fr first
#define se second

#define debug(i,sz,x) F(i,0,sz){cout<<x[i]<<" ";}cout<<endl

ill ABS(ill a) { if ( a < 0 ) return (-a); return a; }

/*
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define cin fin
#define cout fout

ifstream fin("input.txt");
ofstream fout("output.txt");
*/

//CODE STARTS HERE

int a[2000001];

int main()
{
	int n, A;
	ill sm=0;
	DI(n, A);
	F(i, 0, n)
	{
		SI a[i];
		sm+=a[i];
	}
	F(i, 0, n)
		cout<<a[i] - (min(0ll + a[i], A-(n-1)) - max(1LL, A - (sm - a[i]))  + 1)<<" ";
	return 0;
}


#include<cstdio>
#define ll long long

using namespace std;

ll n, A, d[200005], suma1, suma2, a[200005];

int main(){
    scanf("%I64d%I64d", &n, &A);
    for(int i = 0; i < n; ++i){scanf("%I64d", &d[i]); suma1 += d[i];}
    suma2 = n;

    if(n == 1){printf("%I64d", d[0] - 1); return 0;}

    for(int i = 0; i < n; ++i){
        if(A - (suma1 - d[i]) >= 0)a[i] = A - (suma1 - d[i]) - 1;
        else a[i] = 0;
        if(suma2 - 1 + d[i] >= A)a[i] += suma2 - 1 + d[i] - A;
        if(a[i] > d[i])a[i] = d[i];
        if(a[i] < 0)a[i] = 0;
    }

    for(int i = 0; i < n; ++i)printf("%I64d ", a[i]);

    return 0;
}


#include<cstdio>
#define ll long long

using namespace std;

ll n, A, d[200005], suma1, suma2, a[200005];

int main(){
    scanf("%I64d%I64d", &n, &A);
    for(int i = 0; i < n; ++i){scanf("%I64d", &d[i]); suma1 += d[i];}
    suma2 = n;

    if((suma2 > A) || (suma1 < A)){for(int i = 0; i < n; ++i)printf("%I64d ", d[i]);}

    if(n == 1){printf("%d", d[0] - 1); return 0;}

    for(int i = 0; i < n; ++i){
        if(A - (suma1 - d[i]) >= 0)a[i] = A - (suma1 - d[i]) - 1;
        else a[i] = 0;
        if(suma2 - 1 + d[i] >= A)a[i] += suma2 - 1 + d[i] - A;
        if(a[i] > d[i])a[i] = d[i];
        if(a[i] < 0)a[i] = 0;
    }

    for(int i = 0; i < n; ++i)printf("%I64d ", a[i]);

    return 0;
}


#include<cstdio>
#define ll long long

using namespace std;

ll n, A, d[200005], suma1, suma2, a[200005];

int main(){
    scanf("%I64d%I64d", &n, &A);
    for(int i = 0; i < n; ++i){scanf("%I64d", &d[i]); suma1 += d[i];}
    suma2 = n;

    if((suma2 > A) || (suma1 < A)){for(int i = 0; i < n; ++i)printf("%I64d ", d[i]); return 0;}

    if(n == 1){printf("%I64d", d[0] - 1); return 0;}

    for(int i = 0; i < n; ++i){
        if(A - (suma1 - d[i]) >= 0)a[i] = A - (suma1 - d[i]) - 1;
        else a[i] = 0;
        if(suma2 - 1 + d[i] >= A)a[i] += suma2 - 1 + d[i] - A;
        if(a[i] > d[i])a[i] = d[i];
        if(a[i] < 0)a[i] = 0;
    }

    for(int i = 0; i < n; ++i)printf("%I64d ", a[i]);

    return 0;
}


#include<cstdio>
#define ll long long

using namespace std;

ll n, A, d[200005], suma1, suma2, a[200005];

int main(){
    scanf("%I64d%I64d", &n, &A);
    for(int i = 0; i < n; ++i){scanf("%I64d", &d[i]); suma1 += d[i];}
    suma2 = n;

    if(n == 1){printf("%I64d", d[0] - 1); return 0;}

    for(int i = 0; i < n; ++i){
        if(A - (suma1 - d[i]) >= 0)a[i] = A - (suma1 - d[i]) - 1;
        else a[i] = 0;
        if(a[i] < 0)a[i] = 0;
        if(suma2 - 1 + d[i] >= A)a[i] += suma2 - 1 + d[i] - A;
        if(a[i] > d[i])a[i] = d[i];
        if(a[i] < 0)a[i] = 0;
    }

    for(int i = 0; i < n; ++i)printf("%I64d ", a[i]);

    return 0;
}


#include<cstdio>
#define ll long long

using namespace std;

ll n, A, d[200005], suma, r;

int main(){
    scanf("%I64d%I64d", &n, &A);
    for(int i = 0; i < n; ++i){scanf("%I64d", &d[i]); suma += d[i];}

    for(int i = 0; i < n; ++i){
        if(A - (suma - d[i]) >= 0)printf("%I64d ", A - (suma - d[i]));
        else printf("0");
    }

    return 0;
}


#include<iostream>
using namespace std;

long long int a[1000000],d[1000000],ans[1000000],mx[1000000],x,mn[1000000];

int main()
{
long long int n,s,i,maxi,j;
cin>>n>>s;
for(i=0;i<n;i++)
cin>>d[i];
maxi=s-n+1;

for(i=0;i<n;i++)
mx[i]=min(maxi,d[i]);

for(i=0;i<n;i++)
{
x=0;
for(j=0;j<n;j++)
{
if(j==i)continue;
x+=mx[j];
}
mn[i]=s-x;
}

for(i=0;i<n;i++)
{
ans[i]=mn[i]-1+d[i]-mx[i];
if(ans[i]<0)
    ans[i]=0;

}

for(i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
return 0;
}


#include<iostream>
using namespace std;

long long int a[1000000],d[1000000],ans[1000000],mx[1000000],x,mn[1000000];

int main()
{
long long int n,s,i,maxi,j;
cin>>n>>s;
for(i=0;i<n;i++)
cin>>d[i];
maxi=s-n+1;

for(i=0;i<n;i++)
mx[i]=min(maxi,d[i]);

for(i=0;i<n;i++)
{
x=0;
for(j=0;j<n;j++)
{
if(j==i)continue;
x+=mx[j];
}
if(x<s)
mn[i]=s-x;
else
    mn[i]=1;
}

for(i=0;i<n;i++)
{
ans[i]=mn[i]-1+d[i]-mx[i];
if(ans[i]<0)
    ans[i]=0;

}

for(i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
return 0;
}


#include<iostream>
using namespace std;

long long int a[1000000],d[1000000],ans[1000000],mx[1000000],x,mn[1000000];

int main()
{
long long int n,s,i,maxi,j,cons;
cin>>n>>s;
for(i=0;i<n;i++)
cin>>d[i];
maxi=s-n+1;
cons=0;

for(i=0;i<n;i++)
{
mx[i]=min(maxi,d[i]);
cons+=mx[i];
}
for(i=0;i<n;i++)
{
x=cons-mx[i];
if(x<s)
mn[i]=s-x;
else
    mn[i]=1;
}

for(i=0;i<n;i++)
{
ans[i]=mn[i]-1+d[i]-mx[i];
if(ans[i]<0)
    ans[i]=0;

}

for(i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
return 0;
}


#include<iostream>
using namespace std;

long long int a[1000000],d[1000000],ans[1000000],mx[1000000],x,mn[1000000];

int main()
{
long long int n,s,i,maxi,j;
cin>>n>>s;
for(i=0;i<n;i++)
cin>>d[i];
maxi=s-n+1;

for(i=0;i<n;i++)
mx[i]=min(maxi,d[i]);

for(i=0;i<n;i++)
{
x=0;
for(j=0;j<n;j++)
{
if(j==i)continue;
x+=mx[j];
}
mn[i]=s-x;
}

for(i=0;i<n;i++)
{

if(mn[i]!=0)
ans[i]=mn[i]-1+d[i]-mx[i];
else
ans[i]=mn[i]+d[i]-mx[i];
}

for(i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
return 0;
}


#include<iostream>
using namespace std;

long long int a[1000000],d[1000000],ans[1000000],mx[1000000],x,mn[1000000];

int main()
{
long long int n,s,i,maxi,j;
cin>>n>>s;
for(i=0;i<n;i++)
cin>>d[i];
maxi=s-n+1;

for(i=0;i<n;i++)
mx[i]=min(maxi,d[i]);

for(i=0;i<n;i++)
{
x=0;
for(j=0;j<n;j++)
{
if(j==i)continue;
x+=mx[j];
}
mn[i]=s-x;
}

for(i=0;i<n;i++)
ans[i]=mn[i]-1+d[i]-mx[i];

for(i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<vector>
using namespace std;
#define LL long long
#define all(o) (o).begin(),(o).end()
const int maxn = 200010;
int n;LL A;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> A;
	vector<int> d(n);
	for (int i = 0; i < n; i++) scanf("%d", &d[i]);
	LL s = accumulate(all(d), 0LL);
	for (int i = 0; i < n; i++)
	{
		if (i != 0) putchar(' ');
		LL minp = max(1LL, A - (s - d[i]));
		LL maxp = min((LL)d[i], A - (n - 1));
		int ans = minp <= maxp ? (int)((minp - 1) + (d[i] - maxp)) : d[i];
		printf("%d", ans);
	}
	printf("\n");
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<vector>
using namespace std;
#define LL long long
#define all(o) (o).begin(),(o).end()
const int maxn = 200010;
int n, A;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> A;
	vector<int> d(n);
	for (int i = 0; i < n; i++) scanf("%d", &d[i]);
	LL s = accumulate(all(d), 0LL);
	for (int i = 0; i < n; i++)
	{
		if (i != 0) printf(" ");
		LL minp = max(1LL, A - (s - d[i]));
		LL maxp = min(d[i], A - (n - 1));
		LL ans = minp <= maxp ? (minp - 1) + (d[i] - maxp) : (LL)d[i];
		printf("%I64d", ans);
	}
	cout << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<vector>
using namespace std;
#define LL long long
#define all(o) (o).begin(),(o).end()
const int maxn = 200010;
int n;LL A;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> A;
	vector<int> d(n);
	for (int i = 0; i < n; i++) scanf("%d", &d[i]);
	LL s = accumulate(all(d), 0LL);
	for (int i = 0; i < n; i++)
	{
		if (i != 0) printf(" ");
		LL minp = max(1LL, A - (s - d[i]));
		LL maxp = min((LL)d[i], A - (n - 1));
		int ans = minp <= maxp ? (int)((minp - 1) + (d[i] - maxp)) : d[i];
		printf("%d", ans);
	}
	cout << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<vector>
using namespace std;
#define LL long long
#define all(o) (o).begin(),(o).end()
const int maxn = 200010;
int n, A;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> A;
	vector<int> d(n);
	for (int i = 0; i < n; i++) scanf("%d", &d[i]);
	LL s = accumulate(all(d), 0LL);
	for (int i = 0; i < n; i++)
	{
		if (i != 0) printf(" ");
		int minp = max(1LL, A - (s - d[i]));
		int maxp = min(d[i], A - (n - 1));
		int ans = minp <= maxp ? (int)(minp - 1) + (d[i] - maxp) : d[i];
		printf("%d", ans);
	}
	cout << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<vector>
using namespace std;
#define LL long long
#define all(o) (o).begin(),(o).end()
const int maxn = 200010;
int n;LL A;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> A;
	vector<int> d(n);
	for (int i = 0; i < n; i++) scanf("%d", &d[i]);
	LL s = accumulate(all(d), 0LL);
	for (int i = 0; i < n; i++)
	{
		if (i != 0) putchar(' ');
		LL minp = max(1LL, A - (s - d[i]));
		LL maxp = min((LL)d[i], A - (n - 1));
		int ans = minp <= maxp ? (int)((minp - 1) + (d[i] - maxp)) : d[i];
		printf("%d", ans);
	}
	printf("\n");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<vector>
//很精彩的思路，
using namespace std;
#define LL long long
#define all(o) (o).begin(),(o).end()
const int maxn = 200010;
int n;LL A;
int main() {
	int n;
	long long A;
	cin >> n >> A;
	vector<int> d(n);
	for (int i = 0; i < n;i++) scanf("%d", &d[i]);
	long long s = accumulate(all(d), 0LL);
	for (int i = 0; i < n;i++) {
		if (i != 0) putchar(' ');
		LL mi = max(1LL, A - (s - d[i]));        //取到的最小点数
		LL ma = min((LL)d[i], A - (n - 1));      //取到的最大点数
		int ans = mi <= ma ? (int)((mi - 1) + (d[i] - ma)) : d[i];
		printf("%d", ans);
	}

}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<vector>
using namespace std;
#define LL long long
#define all(o) (o).begin(),(o).end()
const int maxn = 200010;
int n;LL A;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> A;
	vector<int> d(n);
	for (int i = 0; i < n; i++) scanf("%d", &d[i]);
	LL s = accumulate(all(d), 0LL);
	for (int i = 0; i < n; i++)
	{
		if (i != 0) putchar(' ');
		LL minp = max(1LL, A - (s - d[i]));
		LL maxp = min((LL)d[i], A - (n - 1));
		int ans = minp <= maxp ? (int)((minp - 1) + (d[i] - maxp)) : d[i];
		printf("%d", ans);
	}
	printf("\n");
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<vector>
using namespace std;
#define LL long long
#define all(o) (o).begin(),(o).end()
const int maxn = 200010;
int n;LL A;
int main() {
	int n;
	long long A;
	cin >> n >> A;
	vector<int> d(n);
	for (int i = 0; i < n;i++) scanf("%d", &d[i]);
	long long s = accumulate(all(d), 0LL);
	for (int i = 0; i < n;i++) {
		if (i != 0) putchar(' ');
		LL mi = max(1LL, A - (s - d[i]));
		LL ma = min((LL)d[i], A - (n - 1));
		int ans = mi <= ma ? (int)((mi - 1) + (d[i] - ma)) : d[i];
		printf("%d", ans);
	}
	puts("");
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int sum,n,sum2=0;
    cin>>n>>sum;
    int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
        sum2+=A[i];
    }
    if(sum2<sum)
    {
        for(int i=0;i<n;i++)
            cout<<A[i]<<" ";
        cout<<endl;
    }
    else if(n==1)
    {
        cout<<A[n-1]-1<<endl;
    }
    else
    {
        for(int i=0;i<n;i++)
        {
            int limit=sum-(n-1),res=0;
            if(A[i]>limit)
                res=A[i]-limit;
            else
            {
                int var=sum2-A[i];
                for(int i=1;i<=A[i];i++)
                {
                    if(sum-i <= var)
                    {
                        res=res+(i-1);
                        break;
                    }
                }
            }
            cout<<res<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int sum,n,sum2=0;
    cin>>n>>sum;
    int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
        sum2+=A[i];
    }
    if(sum2<sum)
    {
        for(int i=0;i<n;i++)
            cout<<A[i]<<" ";
        cout<<endl;
    }
    else if(n==1)
    {
        cout<<A[n-1]-1<<endl;
    }
    else
    {
        for(int i=0;i<n;i++)
        {
            int limit=sum-(n-1),res=0;
            if(A[i]>limit)
                res=A[i]-limit;
            else
            {
                int var=sum2-limit;
                for(int j=1;j<=limit;j++)
                {
                    if(sum-j <= var)
                    {
                        res=res+(j-1);
                        break;
                    }
                }
            }
            cout<<res<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int sum,n,sum2=0;
    cin>>n>>sum;
    int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
        sum2+=A[i];
    }
    if(sum2<sum)
    {
        for(int i=0;i<n;i++)
            cout<<A[i]<<" ";
        cout<<endl;
    }
    else if(n==1)
    {
        cout<<A[n-1]-1<<endl;
    }
    else if(sum2==sum)
    {
        for(int i=0;i<n;i++)
        {
            cout<<A[i]-1<<" ";
        }
        cout<<endl;
    }
    else if(sum2>sum)
    {
        for(int i=0;i<n;i++)
        {
            int limit=sum-(n-1);
            if(A[i]>limit)
                cout<<A[i]-limit<<" ";
            else
                cout<<"0 ";
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    long long int sum,n,sum2=0;
    cin>>n>>sum;
    long long int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
        sum2+=A[i];
    }
    if(sum2<sum)
    {
        for(int i=0;i<n;i++)
            cout<<A[i]<<" ";
        cout<<endl;
    }
    else if(n==1)
    {
        cout<<A[n-1]-1<<endl;
    }
    else if(sum2==sum)
    {
        for(int i=0;i<n;i++)
            cout<<A[i]-1<<" ";
    }
    else
    {
        for(int i=0;i<n;i++)
        {
            long long int limit=sum-(n-1),res=0;
            if(A[i]>limit)
                res=A[i]-limit;

            {
                long long int var=sum2-A[i],f=1;
                //cout<<res<<endl;
                for(int j=1;j<=A[i];j++)
                {
                    if(sum-j <= var)
                    {
                        res=res+(j-1);
                        f=0;
                        break;
                    }
                }
            }
            cout<<res<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int sum,n,sum2=0;
    cin>>n>>sum;
    int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
        sum2+=A[i];
    }
    if(n==1)
    {
        cout<<A[n-1]-1<<endl;
    }
    else if(sum2<sum)
    {
        for(int i=0;i<n;i++)
            cout<<A[i]<<" ";
        cout<<endl;
    }
    else if(sum2==sum)
    {
        for(int i=0;i<n;i++)
        {
            cout<<A[i]-1<<" ";
        }
        cout<<endl;
    }
    else if(sum2>sum)
    {
        for(int i=0;i<n;i++)
        {
            int limit=sum-(n-1);
            if(A[i]>limit)
                cout<<A[i]-limit<<" ";
            else
                cout<<"0 ";
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int sum,n,sum2=0;
    cin>>n>>sum;
    int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
        sum2+=A[i];
    }
    if(sum2<sum)
    {
        for(int i=0;i<n;i++)
            cout<<A[i]<<" ";
        cout<<endl;
    }
    else if(n==1)
    {
        cout<<A[n-1]-1<<endl;
    }
    else
    {
        for(int i=0;i<n;i++)
        {
            int limit=sum-(n-1),res=0;
            if(A[i]>limit)
                res=A[i]-limit;

            {
                int var=sum2-A[i],f=1;
                cout<<res<<endl;
                for(int j=1;j<=min(limit,A[i]);j++)
                {
                    if(sum-j <= var)
                    {
                        res=res+(j-1);
                        f=0;
                        break;
                    }
                }
            }
            cout<<res<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,c=0;
    cin>>n>>m;
    vector<int>v(n);
    int a[m];
    for(int i=0;i<n;i++)cin>>v[i];
    for(int i=0;i<m;i++)cin>>a[i];

    sort(v.rbegin(),v.rend());
    for(int i=0;i<m;i++){
        for(int j=i;j<n;j++){
            if(v[i]>=a[j]){
                c++;
                break;
            }
        }
    }
    cout << c <<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,j=0;
    cin>>n>>m;
    vector<int>v(n);
    int a[m];
    for(int i=0;i<n;i++)cin>>v[i];
    for(int i=0;i<m;i++)cin>>a[i];

    for(int i=0;i<n;i++){
        if(v[i]<=a[j])j++;

        if(j==m)break;
    }
    cout << j <<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,c=0;
    cin>>n>>m;
    vector<int>v(n);
    int a[m];
    for(int i=0;i<n;i++)cin>>v[i];
    for(int i=0;i<m;i++)cin>>a[i];

    sort(v.rbegin(),v.rend());
    for(int i=0;i<m;i++){
        for(int j=i;j<n;j++){
            if(v[j]<=a[i]){
                c++;
                break;
            }
            else break;
        }
    }
    cout << c <<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define sc scanf
#define pf printf
using namespace std;
int main()
{
    int total=0;
    int m, n;   cin>>m>>n; int arr[n], brr[n];
    for(int i=0; i<m; i++) { cin>>arr[i];}
    for(int i=0; i<n; i++)  {cin>>brr[i];}
    for(int i=0; i<m; i++)
    {
        if(total < n && arr[i] <= brr[total]) { total ++;}
    }
    cout<<total<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define sc scanf
#define pf printf
using namespace std;

int main()
{
    int total=0;
    int m, n;   cin>>m>>n; int arr[n], brr[n];
    for(int i=0; i<m; i++) { cin>>arr[i];}
    for(int i=0; i<n; i++)  {cin>>brr[i];}

    for(int i=0, j=0; i<m && j<n; i++)
    {
        if(arr[i] <= brr[j])    {total += 1; j++;}
    }
    cout<<total<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int game[1003],wallet[1003],i,j,n,m;
int main(){
    cin>>n>>m;
    for(i=0;i<n;i++)cin>>game[i];
    for(i=0;i<m;i++)cin>>wallet[i];
    for(i=0;i<n;i++)
    if(wallet[j]>=game[i])
    j++;
        cout<<j;
}


#include<bits/stdc++.h>
#define ll long long
#define sc scanf
#define pf printf
using namespace std;

int main()
{
    int total=0;
    int m, n;   cin>>m>>n; int arr[n], brr[n];
    for(int i=0; i<m; i++) { cin>>arr[i];}
    for(int i=0; i<n; i++)  {cin>>brr[i];}

    for(int i=0, j=0; i<m; i++)
    {
        if(arr[i] <= brr[j])    {total += 1; j++;}

    }
    cout<<total<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define sc scanf
#define pf printf
using namespace std;
int main()
{
    int total=0;
    int m, n;   cin>>m>>n; int arr[n], brr[n];
    for(int i=0; i<m; i++) { cin>>arr[i];}
    for(int i=0; i<n; i++)  {cin>>brr[i];}
    for(int i=0; i<n; i++)
    {
        if(total <= n && arr[i] <= brr[total]) { total ++;}
    }
    cout<<total<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define sc scanf
#define pf printf
using namespace std;
int main()
{
    int m, n;   cin>>m>>n; int arr[n], brr[n];
    for(int i=0; i<m; i++) { cin>>arr[i];}
    for(int i=0; i<n; i++)  {cin>>brr[i];}

    int xx = 0;
    int ans = 0;
    for (int i = 0; i < m; ++i)
      {
          if (xx != n && arr[i] <= brr[xx]){
            ans++;
            xx++;
           }
       }

    cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define sc scanf
#define pf printf
using namespace std;
int main()
{
    int total=0;
    int m, n;   cin>>m>>n; int arr[n], brr[n];
    for(int i=0; i<m; i++) { cin>>arr[i];}
    for(int i=0; i<n; i++)  {cin>>brr[i];}
    for(int i=0; i<m; i++)
    {
        if(total <= n && arr[i] <= brr[total]) { total ++;}
    }
    cout<<total<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define sc scanf
#define pf printf
using namespace std;
int total;
int main()
{
    int m, n;   cin>>m>>n; int arr[n], brr[n];
    for(int i=0; i<m; i++) { cin>>arr[i];}
    for(int i=0; i<n; i++)  {cin>>brr[i];}

    for(int i=0, j=0; i<n; i++)
    {
        if(arr[i] <= brr[j])    {total += 1; j++;}

    }
    cout<<total<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define sc scanf
#define pf printf
using namespace std;
int total;

int main()
{
    int m, n;   cin>>m>>n; int arr[n], brr[n];
    for(int i=0; i<m; i++) { cin>>arr[i];}
    for(int i=0; i<n; i++)  {cin>>brr[i];}

    for(int i=0, j=0; i<m; i++)
    {
        if(arr[i] <= brr[j])    {total += 1; j++;}

    }
    cout<<total<<endl;

    return 0;
}


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

typedef long long ll;
typedef std::pair< int, int > pii;
typedef std::vector< int > vi;
typedef std::vector< pii > vii ;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(), (x).end()
#define fore(i,a,b)  for(int i = (a), vzq_b = (b); i < vzq_b; ++i)
#define forn(i, n)  fore(i,0,n)
#define sz(x)   ( (int)((x).size())  )

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

double const EPS = 1.0E-9 ;
int const mod    = (int)1e9 + 7 ;
inline int read( char*   s ){  return scanf("%s", s) ; }
inline int read(int&x){  return scanf("%d", & ( x ) ); }
inline int read(ll&x){ return scanf("%lld",&x); }
inline int read(double &x){ return scanf("%lf", &x); }
inline int write(int x) { return printf("%d", x); }
inline int write(ll x ) { return printf("%lld", x); }
inline int write(double x){ return printf("%.12f",x); }
inline int write(char c){ putchar(c); }
inline int write(){return 0;}
inline int write(const char* s ) { return printf("%s", s); }
inline int write(std::string const&s){ return write(s.c_str()) ; }
template< typename T> int write(std::vector<T> const& v ) {
    int z = v.size();
    forn( i, z - 1 )
    {
        write(v[i]);
        write(' ');
    }
    if ( z > 0 )
        write( v[ z - 1 ] );
    return z;
}

template< typename ...T> int read(T&...args){
    using swallow = int[];
    swallow w = { 0, ( read(args) ) ... } ;
    return sizeof( w ) / sizeof( w [ 0 ] ) - 1;
}
template< typename T > int read(std::vector<T>&v){
    for(T& t: v ) read(t);
    return  v.size();
}

template< typename ...T > int write(T const& ... args ){
    using swallow = int [];
    swallow  w = { 0, ( write(args), write(' ')) ... } ;
    return sizeof(w) / sizeof( w[0] ) - 1;
}

template< typename ...T >int writeln(T const& ... args ) {
    int r = write(args ... ) ;
    printf("\n");
    return r + 1;
}

inline ll gcd(ll x,ll y) { return y == 0 ? x : gcd(y, x%y); }
inline ll lcm(ll x, ll y){ return x == 0 && y == 0  ? 0 : x/gcd(x,y) * y; }
inline ll powmod(ll x, ll n, ll m = mod ) {
    ll r = 1;
    while(n){
        if (n&1) r = (r*x)%m;
        x = (x*x)%m;
        n/=2;
    }
    return r;
}

static int leap(int y){  return (y % 4 == 0 && y% 100 != 0)  or y % 400 == 0 ; }

static int const month[ 2 ][ 12 ] =
{
    { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
    { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};

int solve();
int main(int argc, char * argv[] )
{
    int t = 1;
    while(t --) solve();
    return 0;
}

/********************************************************/
int solve(){
    int n, m, r = 0;
    read(n, m);
    vi c(n), a(m);
    read(c, a);
    for(int i = 0; i < n && r < m; i ++)
        if(a[r] >= c[i]) r ++;
    write(r);
    return 0;
}


#include <cstdio>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cctype>
#include <cassert>
#include <ciso646>
#include <climits>
#include <cmath>

#include <algorithm>
#include <utility>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <deque>
#include <bitset>
using namespace std;

typedef long long ll;
typedef std::pair< int, int > pii;
typedef std::vector< int > vi;
typedef std::vector< pii > vii ;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(), (x).end()
#define fore(i,a,b)  for(int i = (a), vzq_b = (b); i < vzq_b; ++i)
#define forn(i, n)  fore(i,0,n)
#define sz(x)   ( (int)((x).size())  )

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

double const EPS = 1.0E-9 ;
int const mod    = (int)1e9 + 7 ;
inline int read( char*   s ){  return scanf("%s", s) ; }
inline int read(int&x){  return scanf("%d", & ( x ) ); }
inline int read(ll&x){ return scanf("%lld",&x); }
inline int read(double &x){ return scanf("%lf", &x); }
inline int write(int x) { return printf("%d", x); }
inline int write(ll x ) { return printf("%lld", x); }
inline int write(double x){ return printf("%.12f",x); }
inline int write(char c){ putchar(c); }
inline int write(){return 0;}
inline int write(const char* s ) { return printf("%s", s); }
inline int write(std::string const&s){ return write(s.c_str()) ; }
template< typename T> int write(std::vector<T> const& v ) {
    int z = v.size();
    forn( i, z - 1 )
    {
        write(v[i]);
        write(' ');
    }
    if ( z > 0 )
        write( v[ z - 1 ] );
    return z;
}

template< typename ...T> int read(T&...args){
    using swallow = int[];
    swallow w = { 0, ( read(args) ) ... } ;
    return sizeof( w ) / sizeof( w [ 0 ] ) - 1;
}
template< typename T > int read(std::vector<T>&v){
    for(T& t: v ) read(t);
    return  v.size();
}

template< typename ...T > int write(T const& ... args ){
    using swallow = int [];
    swallow  w = { 0, ( write(args), write(' ')) ... } ;
    return sizeof(w) / sizeof( w[0] ) - 1;
}

template< typename ...T >int writeln(T const& ... args ) {
    int r = write(args ... ) ;
    printf("\n");
    return r + 1;
}

inline ll gcd(ll x,ll y) { return y == 0 ? x : gcd(y, x%y); }
inline ll lcm(ll x, ll y){ return x == 0 && y == 0  ? 0 : x/gcd(x,y) * y; }
inline ll powmod(ll x, ll n, ll m = mod ) {
    ll r = 1;
    while(n){
        if (n&1) r = (r*x)%m;
        x = (x*x)%m;
        n/=2;
    }
    return r;
}

static int leap(int y){  return (y % 4 == 0 && y% 100 != 0)  or y % 400 == 0 ; }

static int const month[ 2 ][ 12 ] =
{
    { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
    { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};

int solve();
int main(int argc, char * argv[] )
{
    int t = 1;
    while(t --) solve();
    return 0;
}

/********************************************************/
int solve(){
    int n, m, r = 0;
    read(n, m);
    vi c(n), a(m);
    read(c);
    read(a);
    for(int i = 0; i < n && r < m; i ++)
        if(a[r] >= c[i]) r ++;
    write(r);
    return 0;
}


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

typedef long long ll;
typedef std::pair< int, int > pii;
typedef std::vector< int > vi;
typedef std::vector< pii > vii ;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(), (x).end()
#define fore(i,a,b)  for(int i = (a), vzq_b = (b); i < vzq_b; ++i)
#define forn(i, n)  fore(i,0,n)
#define sz(x)   ( (int)((x).size())  )

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

double const EPS = 1.0E-9 ;
int const mod    = (int)1e9 + 7 ;
inline int read( char*   s ){  return scanf("%s", s) ; }
inline int read(int&x){  return scanf("%d", & ( x ) ); }
inline int read(ll&x){ return scanf("%lld",&x); }
inline int read(double &x){ return scanf("%lf", &x); }
inline int write(int x) { return printf("%d", x); }
inline int write(ll x ) { return printf("%lld", x); }
inline int write(double x){ return printf("%.12f",x); }
inline int write(char c){ putchar(c); }
inline int write(){return 0;}
inline int write(const char* s ) { return printf("%s", s); }
inline int write(std::string const&s){ return write(s.c_str()) ; }
template< typename T> int write(std::vector<T> const& v ) {
    int z = v.size();
    forn( i, z - 1 )
    {
        write(v[i]);
        write(' ');
    }
    if ( z > 0 )
        write( v[ z - 1 ] );
    return z;
}

template< typename T > int read(std::vector<T>&v){
    for(T& t: v ) read(t);
    return  v.size();
}
template< typename ...T> int read(T&...args){
    using swallow = int[];
    swallow w = { 0, ( read(args) ) ... } ;
    return sizeof( w ) / sizeof( w [ 0 ] ) - 1;
}
template< typename ...T > int write(T const& ... args ){
    using swallow = int [];
    swallow  w = { 0, ( write(args), write(' ')) ... } ;
    return sizeof(w) / sizeof( w[0] ) - 1;
}

template< typename ...T >int writeln(T const& ... args ) {
    int r = write(args ... ) ;
    printf("\n");
    return r + 1;
}

inline ll gcd(ll x,ll y) { return y == 0 ? x : gcd(y, x%y); }
inline ll lcm(ll x, ll y){ return x == 0 && y == 0  ? 0 : x/gcd(x,y) * y; }
inline ll powmod(ll x, ll n, ll m = mod ) {
    ll r = 1;
    while(n){
        if (n&1) r = (r*x)%m;
        x = (x*x)%m;
        n/=2;
    }
    return r;
}

static int leap(int y){  return (y % 4 == 0 && y% 100 != 0)  or y % 400 == 0 ; }

static int const month[ 2 ][ 12 ] =
{
    { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
    { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};

int solve();
int main(int argc, char * argv[] )
{
    int t = 1;
    while(t --) solve();
    return 0;
}

/********************************************************/
int solve(){
    int n, m, r = 0;
    read(n, m);
    vi c(n), a(m);
    read(c, a);
    for(int i = 0; i < n && r < m; i ++)
        if(a[r] >= c[i]) r ++;
    write(r);
    return 0;
}


#if 1
#include <cstdio>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cctype>
#include <cassert>
#include <ciso646>
#include <climits>
#include <cmath>

#include <algorithm>
#include <utility>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <deque>
#include <bitset>
using namespace std;

typedef long long ll;
typedef std::pair< int, int > pii;
typedef std::vector< int > vi;
typedef std::vector< pii > vii ;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(), (x).end()
#define fore(i,a,b)  for(int i = (a), vzq_b = (b); i < vzq_b; ++i)
#define forn(i, n)  fore(i,0,n)
#define sz(x)   ( (int)((x).size())  )

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

double const EPS = 1.0E-9 ;
int const mod    = (int)1e9 + 7 ;
inline int read( char*   s ){  return scanf("%s", s) ; }
inline int read(int&x){  return scanf("%d", & ( x ) ); }
inline int read(ll&x){ return scanf("%lld",&x); }
inline int read(double &x){ return scanf("%lf", &x); }
inline int write(int x) { return printf("%d", x); }
inline int write(ll x ) { return printf("%lld", x); }
inline int write(double x){ return printf("%.12f",x); }
inline int write(char c){ putchar(c); }
inline int write(){return 0;}
inline int write(const char* s ) { return printf("%s", s); }
inline int write(std::string const&s){ return write(s.c_str()) ; }
template< typename T> int write(std::vector<T> const& v ) {
    int z = v.size();
    forn( i, z - 1 )
    {
        write(v[i]);
        write(' ');
    }
    if ( z > 0 )
        write( v[ z - 1 ] );
    return z;
}

template< typename ...T> int read(T&...args){
    using swallow = int[];
    swallow w = { 0, ( read(args) ) ... } ;
    return sizeof( w ) / sizeof( w [ 0 ] ) - 1;
}
template< typename T > int read(std::vector<T>&v){
    for(T& t: v ) read(t);
    return  v.size();
}

template< typename ...T > int write(T const& ... args ){
    using swallow = int [];
    swallow  w = { 0, ( write(args), write(' ')) ... } ;
    return sizeof(w) / sizeof( w[0] ) - 1;
}

template< typename ...T >int writeln(T const& ... args ) {
    int r = write(args ... ) ;
    printf("\n");
    return r + 1;
}

inline ll gcd(ll x,ll y) { return y == 0 ? x : gcd(y, x%y); }
inline ll lcm(ll x, ll y){ return x == 0 && y == 0  ? 0 : x/gcd(x,y) * y; }
inline ll powmod(ll x, ll n, ll m = mod ) {
    ll r = 1;
    while(n){
        if (n&1) r = (r*x)%m;
        x = (x*x)%m;
        n/=2;
    }
    return r;
}

static int leap(int y){  return (y % 4 == 0 && y% 100 != 0)  or y % 400 == 0 ; }

static int const month[ 2 ][ 12 ] =
{
    { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
    { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
#endif
int solve();
int main(int argc, char * argv[] )
{
    int t = 1;
    while(t --) solve();
    return 0;
}

/********************************************************/
int solve(){
    int n, m, r = 0;
    read(n, m);
    vi c(n), a(m);
    read(c, a);
    for(int i = 0; i < n && r < m; i ++)
        if(a[r] >= c[i]) r ++;
    write(r);
    return 0;
}


#include <cstdio>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cctype>
#include <cassert>
#include <ciso646>
#include <climits>
#include <cmath>

#include <algorithm>
#include <utility>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <deque>
#include <bitset>
using namespace std;

typedef long long ll;
typedef std::pair< int, int > pii;
typedef std::vector< int > vi;
typedef std::vector< pii > vii ;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(), (x).end()
#define fore(i,a,b)  for(int i = (a), vzq_b = (b); i < vzq_b; ++i)
#define forn(i, n)  fore(i,0,n)
#define sz(x)   ( (int)((x).size())  )

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

double const EPS = 1.0E-9 ;
int const mod    = (int)1e9 + 7 ;
inline int read( char*   s ){  return scanf("%s", s) ; }
inline int read(int&x){  return scanf("%d", & ( x ) ); }
inline int read(ll&x){ return scanf("%lld",&x); }
inline int read(double &x){ return scanf("%lf", &x); }
inline int write(int x) { return printf("%d", x); }
inline int write(ll x ) { return printf("%lld", x); }
inline int write(double x){ return printf("%.12f",x); }
inline int write(char c){ putchar(c); }
inline int write(){return 0;}
inline int write(const char* s ) { return printf("%s", s); }
inline int write(std::string const&s){ return write(s.c_str()) ; }
template< typename T> int write(std::vector<T> const& v ) {
    int z = v.size();
    forn( i, z - 1 )
    {
        write(v[i]);
        write(' ');
    }
    if ( z > 0 )
        write( v[ z - 1 ] );
    return z;
}

template< typename T > int read(std::vector<T>&v){
    for(T& t: v ) read(t);
    return  v.size();
}
template< typename ...T> int read(T&...args){
    using swallow = int[];
    swallow w = { 0, ( read(args) ) ... } ;
    return sizeof( w ) / sizeof( w [ 0 ] ) - 1;
}
template< typename ...T > int write(T const& ... args ){
    using swallow = int [];
    swallow  w = { 0, ( write(args), write(' ')) ... } ;
    return sizeof(w) / sizeof( w[0] ) - 1;
}

template< typename ...T >int writeln(T const& ... args ) {
    int r = write(args ... ) ;
    printf("\n");
    return r + 1;
}

inline ll gcd(ll x,ll y) { return y == 0 ? x : gcd(y, x%y); }
inline ll lcm(ll x, ll y){ return x == 0 && y == 0  ? 0 : x/gcd(x,y) * y; }
inline ll powmod(ll x, ll n, ll m = mod ) {
    ll r = 1;
    while(n){
        if (n&1) r = (r*x)%m;
        x = (x*x)%m;
        n/=2;
    }
    return r;
}

static int leap(int y){  return (y % 4 == 0 && y% 100 != 0)  or y % 400 == 0 ; }

static int const month[ 2 ][ 12 ] =
{
    { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
    { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};

int solve();
int main(int argc, char * argv[] )
{
    int t = 1;
    while(t --) solve();
    return 0;
}

/********************************************************/
int solve(){
    int n, m, r = 0;
    read(n, m);
    vi c(n), a(m);
    read(c, a);
    for(int i = 0; i < n && r < m; i ++)
        if(a[r] >= c[i]) r ++;
    write(r);
    return 0;
}


#include<iostream>
using namespace std;
int main(){
	long int i, j, n, m;
	cin>>n>>m;
	long int c[n], a[m];
	for(i = 0; i < n; i++)cin>>c[i];
	for(i = 0; i < m; i++)cin>>a[i];
	long int count = 0;
	j = 0;
	for(i = 0; i < n; i++){
		if(j == m-1){
			break;
		}
		if(c[i] <= a[j]){
			j++;count++;
		}
	}
	cout<<count;
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	long int i, j, n, m;
	cin>>n>>m;
	long int c[n], a[m];
	for(i = 0; i < n; i++)cin>>c[i];
	for(i = 0; i < m; i++)cin>>a[i];
	long int count = 0;
	j = 0;
	for(i = 0; i < n; i++){
		if(c[i] <= a[j]){
			j++;count++;
		}
	}
	cout<<count;
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	long int i, j, n, m;
	cin>>n>>m;
	long int c[n], a[m];
	for(i = 0; i < n; i++)cin>>c[i];
	for(i = 0; i < m; i++)cin>>a[i];
	long int count = 0;
	j = 0;
	for(i = 0; i < n; i++){
		if(j == m){
			break;
		}
		if(c[i] <= a[j]){
			j++;count++;
		}
	}
	cout<<count;
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int i, j, n, m;
	cin>>n>>m;
	int c[n], a[m];
	for(i = 0; i < n; i++)cin>>c[i];
	for(i = 0; i < m; i++)cin>>a[i];
	int count = 0;
	j = 0;
	for(i = 0; i < n; i++){
		if(c[i] <= a[j]){
			j++;count++;
		}
	}
	cout<<count;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m;
	cin>>n>>m;
	int c=0;
	int bnext = 1;
	int sum = 0;
	int A[n] = {}, B[m] = {};
	for(int i=0; i<n; i++)
		cin>>A[i];
	for(int i2=0; i2<m; i2++)
		cin>>B[i2];
	while(c < n)
	{
		if(B[0]<A[c])
		{
		c++;
		continue;
		}
		else
		{
			sum++;
			B[0]=B[0]-A[c];
			swap(B[0],B[bnext]);
			if(bnext<m)
			{
			bnext++;
			}
			else
			{
			bnext=1;
			}
		}
		c++;
	}
	cout<<sum;
	sum=0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m;
	cin>>n>>m;
	int c=0;
	int bnext = 1;
	int sum = 0;
	int A[n+1] = {0};
	int B[m+1] = {0};
	for(int i=0; i<n; i++)
		cin>>A[i];
	for(int i2=0; i2<m; i2++)
		cin>>B[i2];
	while(c < n)
	{
		if(B[0]<A[c])
		{
		c++;
		continue;
		}
		else
		{
			sum++;
			B[0]-=A[c];
			swap(B[0],B[bnext]);
			if(bnext<m)
			{
			bnext++;
			}
			else
			{
			bnext=1;
			}
		}
		c++;
	}
	cout<<sum<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m;
	cin>>n>>m;
	int c=0;
	int bnext = 1;
	int sum = 0;
	int A[n] = {};
	int B[m] = {};
	for(int i=0; i<n; i++)
		cin>>A[i];
	for(int i2=0; i2<m; i2++)
		cin>>B[i2];
	while(c < n)
	{
		if(B[0]<A[c])
		{
		c++;
		continue;
		}
		else
		{
			sum++;
			B[0]-=A[c];
			swap(B[0],B[bnext]);
			if(bnext<m)
			{
			bnext++;
			}
			else
			{
			bnext=1;
			}
		}
		c++;
	}
	cout<<sum<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m;
	cin>>n>>m;
	int c=0;
	int bnext = 1;
	int sum = 0;
	int A[n] = {}, B[m] = {};
	for(int i=0; i<n; i++)
		cin>>A[i];
	for(int i2=0; i2<m; i2++)
		cin>>B[i2];
	while(c < n)
	{
		if(B[0]<A[c])
		{
		c++;
		continue;
		}
		else
		{
			sum++;
			B[0]=B[0]-A[c];
			swap(B[0],B[bnext]);
			if(bnext<m)
			{
			bnext++;
			}
			else
			{
			bnext=1;
			}
		}
		c++;
	}
	cout<<sum;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m;
	cin>>n>>m;
	int c=0;
	int bnext = 1;
	int sum = 0;
	int A[n] = {};
	int B[m] = {};
	for(int i=0; i<n; i++)
		cin>>A[i];
	for(int i2=0; i2<m; i2++)
		cin>>B[i2];
	while(c < n)
	{
		if(B[0]<A[c])
		{
		c++;
		continue;
		}
		else
		{
			sum++;
			B[0]-=A[c];
			swap(B[0],B[bnext]);
			if(bnext<m)
			{
			bnext++;
			}
			else
			{
			bnext=1;
			}
		}
		c++;
	}
	cout<<sum;
	sum=0;
}


# include <bits/stdc++.h>
# define pb push_back
# define ll long long
# define fi first
# define se second
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define mkp make_pair
//# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

using namespace std;

int q , w , e;

int main()
{
	speed;

    vector<pair<int,int>>vc;

    int n , m ;
    cin >> n >> m ;
    int bozi[n];
    int kup[m];
    for(int i = 0 ; i < n ; i ++ ){
        cin >> bozi[i] ;
    }
    for(int i = 0 ; i < m ; i ++ ){
        cin >> kup[i] ;
    }
    int k = 0 ;
    for(int i = 0 ; i < n ; i ++ ){
        if(kup[k]>=bozi[i]){
            q++;
            if( k < m ){
            k ++ ;
            }
        }
    }
    cout<<q;

	time;
}


# include <bits/stdc++.h>
# define pb push_back
# define ll long long
# define fi first
# define se second
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define mkp make_pair
//# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

using namespace std;

int q , w , e;

int main()
{
	speed;

    vector<pair<int,int>>vc;

    int n , m ;
    cin >> n >> m ;
    int bozi[n];
    int kup[m];
    for(int i = 0 ; i < n ; i ++ ){
        cin >> bozi[i] ;
    }
    for(int i = 0 ; i < m ; i ++ ){
        cin >> kup[i] ;
    }
    int k = 0 ;
    for(int i = 0 ; i < n ; i ++ ){
        if(kup[k]>=bozi[i]){
            q++;
            if( k < m ){
            k ++ ;
            }
        }
    }
    cout<<min(q,m);

	time;
}


# include <bits/stdc++.h>
# define pb push_back
# define ll long long
# define fi first
# define se second
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define mkp make_pair
//# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

using namespace std;

int q , w , e;

int main()
{
	speed;

    vector<pair<int,int>>vc;

    int n , m ;
    cin >> n >> m ;
    int bozi[n];
    int kup[m];
    for(int i = 0 ; i < n ; i ++ ){
        cin >> bozi[i] ;
    }
    for(int i = 0 ; i < m ; i ++ ){
        cin >> kup[i] ;
    }
    int k = 0 ;
    for(int i = 0 ; i < n ; i ++ ){
        if(kup[k]>=bozi[i]){
            q++;
            k ++ ;
        }
    }
    cout<<q;

	time;
}


#include<iostream>
#include<cctype>
#include<stdlib.h>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define PI acos(-1.0)
#define all(v) v.begin(),v.end()
#define for0(i, n) for (ll  i = 0; i < (ll)(n); i++) // 0 based indexing
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--) // reverse 0 based.
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
using namespace std;
map <ll,ll> frequency (vector<ll> v) {map<ll,ll> m;for (ll i=0;i<v.size();i++) {if (m.find(v[i])!=m.end()) m[v[i]]++; else {m.insert({v[i],1});}}return m;}
void input(vector<ll>& v,ll n){ for0(i,n) { ll in; cin>>in; v.pb(in);} }
void output(vector<ll> v) { for0(i,v.size()) cout<<v[i]<<" "; }
void solve()
{
    ll n,m,i,j,k=0;
    cin>>n>>m;
    vector<ll> a,c;
    input(c,n);
    input(a,m);
    for (i=0;i<n;i++)
    {
        if (k<m && a[k]>=c[i])
            k++;
    }
    cout<<k<<endl;
}

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


#include<iostream>
#include<cctype>
#include<stdlib.h>
#include<math.h>
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
using namespace std;
void input(vector<long>& v,long n){ for(long i=0;i<n;i++) { long in; cin>>in; v.push_back(in);} }
//void output(vector<long> v) { for(long i=0;i<v.size();i++) cout<<v[i]<<" "; }
int solve()
{
   long n,m;
   cin>>n>>m;
   long c[n],a[m];
   for(long i=0;i<n;i++)
    cin>>c[i];
   for(long i=0;i<m;i++)
    cin>>a[i];
   long k=0,ct=0;
   for(long i=0;i<m;i++)
   {
       for(long j=k;j<n;j++)
       {
           if(a[i]>c[j])
           {
               ct++;
               k=j+1;
               break;
           }
       }
   }
   cout<<ct<<endl;
   return 0;
}
int main()
{

    solve();
    return 0;
}


#include<iostream>
#include<cctype>
#include<stdlib.h>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define PI acos(-1.0)
#define all(v) v.begin(),v.end()
#define for0(i, n) for (ll  i = 0; i < (ll)(n); i++) // 0 based indexing
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--) // reverse 0 based.
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
using namespace std;
map <ll,ll> frequency (vector<ll> v) {map<ll,ll> m;for (ll i=0;i<v.size();i++) {if (m.find(v[i])!=m.end()) m[v[i]]++; else {m.insert({v[i],1});}}return m;}
void input(vector<ll>& v,ll n){ for0(i,n) { ll in; cin>>in; v.pb(in);} }
void output(vector<ll> v) { for0(i,v.size()) cout<<v[i]<<" "; }
void solve()
{
    ll n,m,k=0,ans=0;
    cin>>n>>m;
    ll a[n];
    ll b[m];
    for (int i=0;i<n;i++)
        cin>>a[i];
    for (int j=0;j<m;j++)
        cin>>b[j];
    for (int i=0;i<n;i++)
    {
        if (b[k]>=a[i])
            ans++;
            k++;
    }
    cout<<ans<<endl;

}

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


#include<iostream>
#include<cctype>
#include<stdlib.h>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define PI acos(-1.0)
#define all(v) v.begin(),v.end()
#define for0(i, n) for (ll  i = 0; i < (ll)(n); i++) // 0 based indexing
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--) // reverse 0 based.
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
using namespace std;
map <ll,ll> frequency (vector<ll> v) {map<ll,ll> m;for (ll i=0;i<v.size();i++) {if (m.find(v[i])!=m.end()) m[v[i]]++; else {m.insert({v[i],1});}}return m;}
void input(vector<ll>& v,ll n){ for0(i,n) { ll in; cin>>in; v.pb(in);} }
void output(vector<ll> v) { for0(i,v.size()) cout<<v[i]<<" "; }
void solve()
{
   long n,m;
   cin>>n>>m;
   long c[n],a[m];
   for(long i=0;i<n;i++)
    cin>>c[i];
   for(long i=0;i<m;i++)
    cin>>a[i];
   long k=0,ct=0;
   for(long i=0;i<n;i++)
   {
     if(a[k]>=c[i])
        {
               ct++;
               k++;
        }
   }
   cout<<ct<<endl;
}

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


#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define pb push_back
#define mp make_pair
#define bs binary_search
const int mod = 1e9 + 7;
const int SZ=1e2+5;

using namespace std;

int main()
{
	/**///------------------------///**/
	/**/ios::sync_with_stdio(false);/**/
	/**///------------------------///**/
	int n , m,c,a;
	cin >> n >> m;
	vector<int> nums;
	vector<int> note;
	for(int i = 0; i < n; i++)
	{
		cin >> c;
		nums.pb(c);
	}
	for(int j = 0; j < m; j++)
	{
		cin >> a;
		note.pb(a);
	}
	int ans = 0,tag = 0;;
	for(int i = 0; i < n; i++)
	{
		if(note.size()==0)break;
		if(note[tag] >= nums[i])
		{
			ans++;
			tag++;
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define pb push_back
#define mp make_pair
#define bs binary_search
const int mod = 1e9 + 7;
const int SZ=1e2+5;

using namespace std;

int main()
{
	/**///------------------------///**/
	/**/ios::sync_with_stdio(false);/**/
	/**///------------------------///**/
	int n , m,c,a;
	cin >> n >> m;
	vector<int> nums;
	vector<int> note;
	for(int i = 0; i < n; i++)
	{
		cin >> c;
		nums.pb(c);
	}
	for(int j = 0; j < m; j++)
	{
		cin >> a;
		note.pb(a);
	}
	int ans = 0,tag = 0;;
	for(int i = 0; i < n; i++)
	{
		if(note.size()==0)break;
		if(note[tag] >= nums[i])
		{
			ans++;
			tag++;
		}
	}
	cout << ans;
}


#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define pb push_back
#define mp make_pair
#define bs binary_search
const int mod = 1e9 + 7;
const int SZ=1e2+5;

using namespace std;

int main()
{
	/**///------------------------///**/
	/**/ios::sync_with_stdio(false);/**/
	/**///------------------------///**/

	cout << 14;
}


#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define pb push_back
#define mp make_pair
#define bs binary_search
const int mod = 1e9 + 7;
const int SZ=1e2+5;

using namespace std;

int main()
{
	/**///------------------------///**/
	/**/ios::sync_with_stdio(false);/**/
	/**///------------------------///**/
	int n , m,c,a;
	cin >> n >> m;
	vector<int> nums;
	vector<int> note;
	for(int i = 0; i < n; i++)
	{
		cin >> c;
		nums.pb(c);
	}
	for(int j = 0; j < m; j++)
	{
		cin >> a;
		note.pb(a);
	}
	int ans = 0,tag = 0;;
	for(int i = 0; i < n; i++)
	{
		if(note.size()==tag)break;
		if(note[tag] >= nums[i])
		{
			ans++;
			tag++;
		}
	}
	cout << ans << endl;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    int c[n], a, stop = 0, games_bought = 0;

    for(int i = 0; i < n; i++) {
        cin >> c[i];
    }
    for(int j = 0; j < m; j++) {
        cin >> a;
        for(int i = stop; i < n; i++) {
            if (a >= c[i]) {
                games_bought++;
                stop = i+1;
                break;
            }
            if (i == n-1) {
                cout << 0;
                return 0;
            }
        }
    }

    cout << games_bought;

    return 0;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    int c[n], a, stop = 0, games_bought = 0;

    for(int i = 0; i < n; i++) {
        cin >> c[i];
    }

    for(int j = 0; j < m; j++) {
        cin >> a;

        for(int i = stop; i < n; i++) {
            if (a >= c[i]) {
                games_bought++;
                stop = i+1;
                break;
            }
            if (i == n-1 && games_bought == 0) {
                cout << 0;
                return 0;
            }
        }

    }

    cout << games_bought;

    return 0;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    int c[n], a, stop = 0, games_bought = 0;

    for(int i = 0; i < n; i++) {
        cin >> c[i];
    }

    for(int j = 0; j < m; j++) {
        cin >> a;

        for(int i = stop; i < n; i++) {
            if (a >= c[i]) {
                games_bought++;
                stop = i+1;
                break;
            }
            if (i == n-1) {
                cout << 0;
                return 0;
            }
        }

    }

    cout << games_bought;

    return 0;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    int c[n], a, stop = 0, games_bought = 0;

    for(int i = 0; i < n; i++) {
        cin >> c[i];
    }

    for(int j = 0; j < m; j++) {
        cin >> a;

        for(int i = stop; i < n; i++) {
            if (a >= c[i]) {
                games_bought++;
                stop = i+1;
                break;
            }
            if (i == n-1 && games_bought == 0) {
                cout << 0;
                return 0;
            }
            if (i == n-1) {
                stop = i+1;
            }
        }

    }

    cout << games_bought;

    return 0;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    int c[n], a, stop = 0, games_bought = 0;

    for(int i = 0; i < n; i++) {
        cin >> c[i];
    }

    for(int j = 0; j < m; j++) {
        cin >> a;

        for(int i = stop; i < n; i++) {
            if (a >= c[i]) {
                games_bought++;
                stop = i+1;
                break;
            }
        }

    }

    cout << games_bought;

    return 0;
}


#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(){
 queue<int>a,b;
 int x,y;
 int n,m,g=0;
 cin>>n>>m;
 for(int i=0;i<n;i++){
    cin>>x;
    a.push(x);
 }
 for(int i=0;i<m;i++){
    cin>>y;
    b.push(y);
 }
 while(a.empty()==0&&b.empty()==0){
    if(b.front()>=a.front()){
        g++;
        a.pop();
        b.pop();
    }
    else{
        a.pop();
    }
 }
cout<<g;

}


#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(){
 queue<int>a,b;
 int x,y;
 int n,m,g=0;
 cin>>n>>m;
 for(int i=0;i<n;i++){
    cin>>x;
    a.push(x);

 }
 for(int i=0;i<m;i++){
    cin>>y;
    b.push(y);

 }
 while(a.empty()==0){
    if(b.front()>=a.front()){
        g++;
        a.pop();
        b.pop();

    }
    else{
        a.pop();

    }

 }

cout<<g;

}


#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(){
 queue<int>a,b;
 int x,y;
 int n,m,g=0;
 cin>>n>>m;
 for(int i=0;i<n;i++){
    cin>>x;
    a.push(x);

 }
 for(int i=0;i<m;i++){
    cin>>y;
    b.push(y);

 }
 while(a.empty()==0||b.empty()==0){
    if(b.front()>=a.front()){
        g++;
        a.pop();
        b.pop();

    }
    else{
        a.pop();

    }

 }

cout<<g;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,x=0,m,a[1000+5],b[1000+5],y=0;
cin>>n>>m;
for(int i=0;i<n;i++){
    cin>>a[i];
}
for(int i=0;i<m;i++){
    cin>>b[i];
}
for(int i=0;i<n;i++){
    if(b[y]>=a[i]){
        y++;
    }
}
cout<<y;
}


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

int main(){

	int n,m; cin>>n>>m;
	int arr[n]; int ar[m];
	for(int i = 0; i < n; i++){
		cin>>arr[i];
	}
	for(int i = 0; i < m; i++){
		cin>>ar[i];
	}
	int j = 0; int co = 0;
	for(int i = 0; i < n; i++){
		if(arr[i] < ar[j]){ co++; j++;}
	}
	cout<<co<<"\n";

}


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

int main(){

	int n,m; cin>>n>>m;
	int arr[n]; int ar[m];
	for(int i = 0; i < n; i++){
		cin>>arr[i];
	}
	for(int i = 0; i < m; i++){
		cin>>ar[i];
	}
	int j = 0; int co = 0;
	for(int i = 0; i < n; i++){
		if(arr[i] <= ar[j]){ co++; j++;}
	}
	cout<<co<<"\n";

}


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

int main(){

	int n,m; cin>>n>>m;
	int arr[n]; int ar[m];
	for(int i = 0; i < n; i++){
		cin>>arr[i];
	}
	for(int i = 0; i < m; i++){
		cin>>ar[i];
	}
	int j = 0; int co = 0;
	for(int i = 0; i < n; i++){
		if(arr[i] <= ar[j] && j < m){ co++; j++;}
	}
	cout<<co<<"\n";

}


// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}

int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin >> n >> m;
    int c[n+1];
    rep(i,1,n+1) cin >> c[i];
    int a[m+1];
    rep(i,1,m+1) cin >> a[i];
    int cur=1;
    int ans=0;
    for(int i=1; i<=n; i++){
        if(cur>m) break;
        if(a[cur]>=c[i]){
            ans++;
            cur++;
        }
    }
    cout << ans;
    return 0;
}