#include<bits/stdc++.h>
#define rep1(i,n,a) for(int i=0;i<n;i+=a)
#define rep2(i,n,a) for(int i=a;i<n;i++)
#define rep3(n)     for(int i=0;i<n;i++)
#define inarr(arr,n) rep1(i,n,1)cin>>arr[i]
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define trav(a,x) for(auto x:a)
#define endl "\n"
#define eb emplace_back
#define fr first
#define sc second
#define gcd(a,b) __gcd(a,b)
#define pres(a,x) a.find(x)!=a.end()
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define psi pair<string,int>
#define pss pair<string,string>
#define pll pair<ll,ll>
#define vec vector<int>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret return 0
#define pi 3.1415926536
#define hell 1000000007
#define narak 998244353
const int inf1=1e9;
const ll inf2=1e18;
using namespace std;
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
// syntax for min priority_queue of pairs
// priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
int solve(){
  int n,q;cin>>n>>q;
  int arr[q+1]={0};
  int dp=1;
  int s=0;
  queue<int> v[n+1];
  int no=1;
  int mp[q+1];
  for(int i=1;i<=q;i++){
      int t=1;
      cin>>t;
      if(t==1){
        s++;
        int x;cin>>x;
        v[x].push(no);
        mp[no]=x;
        no++;
      }
      if(t==2){
          int x;cin>>x;
          while(!v[x].empty()){
              int k=v[x].front();
              if(arr[k]==0){
                  s--;
                  arr[k]=1;
              }
              v[x].pop();
          }
      }
      if(t==3){
          int x;cin>>x;
          for(int j=dp;j<=x;j++){
              if(arr[j]==0){
                  v[mp[j]].pop();
                  arr[j]=1;
                  s--;
              }
          }
          dp=x+1;
      }
      cout<<s<<endl;
      /**cout<<"--------------"<<endl;
      for(int j=1;j<=n;j++){
          if(v[j].size()==0)continue;cout<<j<<" ";
          for(auto k:v[j])cout<<k<<" ";cout<<endl;
      }
      cout<<"--------------"<<endl;**/
      //for(int j=1;j<=i;j++)cout<<arr[j]<<" ";cout<<endl;

  }
  ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}


#include<bits/stdc++.h>
#define rep1(i,n,a) for(int i=0;i<n;i+=a)
#define rep2(i,n,a) for(int i=a;i<n;i++)
#define rep3(n)     for(int i=0;i<n;i++)
#define inarr(arr,n) rep1(i,n,1)cin>>arr[i]
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define trav(a,x) for(auto x:a)
#define endl "\n"
#define eb emplace_back
#define fr first
#define sc second
#define gcd(a,b) __gcd(a,b)
#define pres(a,x) a.find(x)!=a.end()
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define psi pair<string,int>
#define pss pair<string,string>
#define pll pair<ll,ll>
#define vec vector<int>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret return 0
#define pi 3.1415926536
#define hell 1000000007
#define narak 998244353
const int inf1=1e9;
const ll inf2=1e18;
using namespace std;
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
// syntax for min priority_queue of pairs
// priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
int solve(){
  int n,q;cin>>n>>q;
  int arr[n+1]={0};
  int dp=1;
  int s=0;
  vector<int> v[n+1];
  for(int i=1;i<=q;i++){
      int t=1;
      cin>>t;
      if(t==1){
        s++;
        int x;cin>>x;
        v[x].pb(i);
      }
      if(t==2){
          int x;cin>>x;
          for(auto j:v[x]){
              if(arr[j]==0){
                  arr[j]=1;
                  s--;
              }
          }
          v[x].clear();
      }
      if(t==3){
          int x;cin>>x;
          for(int j=dp;j<=x;j++){
              if(arr[j]==0){
                  arr[j]=1;
                  s--;
              }
          }
          dp=x+1;
      }
      cout<<s<<endl;
  }
  ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}


#include<bits/stdc++.h>
#define rep1(i,n,a) for(int i=0;i<n;i+=a)
#define rep2(i,n,a) for(int i=a;i<n;i++)
#define rep3(n)     for(int i=0;i<n;i++)
#define inarr(arr,n) rep1(i,n,1)cin>>arr[i]
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define trav(a,x) for(auto x:a)
#define endl "\n"
#define eb emplace_back
#define fr first
#define sc second
#define gcd(a,b) __gcd(a,b)
#define pres(a,x) a.find(x)!=a.end()
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define psi pair<string,int>
#define pss pair<string,string>
#define pll pair<ll,ll>
#define vec vector<int>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret return 0
#define pi 3.1415926536
#define hell 1000000007
#define narak 998244353
const int inf1=1e9;
const ll inf2=1e18;
using namespace std;
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
// syntax for min priority_queue of pairs
// priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
int solve(){
  int n,q;cin>>n>>q;
  int arr[q+1]={0};
  int dp=1;
  int s=0;
  queue<int> v[n+1];
  int no=1;
  map<int,int> mp;
  for(int i=1;i<=q;i++){
      int t=1;
      cin>>t;
      if(t==1){
        s++;
        int x;cin>>x;
        v[x].push(no);
        mp[no]=x;
        no++;
      }
      if(t==2){
          int x;cin>>x;
          while(!v[x].empty()){
              int k=v[x].front();
              if(arr[k]==0){
                  s--;
                  arr[k]=1;
              }
              v[x].pop();
          }
      }
      if(t==3){
          int x;cin>>x;
          for(int j=dp;j<=x;j++){
              if(arr[j]==0){
                  v[mp[j]].pop();
                  arr[j]=1;
                  s--;
              }
          }
          dp=x+1;
      }
      cout<<s<<endl;
      /**cout<<"--------------"<<endl;
      for(int j=1;j<=n;j++){
          if(v[j].size()==0)continue;cout<<j<<" ";
          for(auto k:v[j])cout<<k<<" ";cout<<endl;
      }
      cout<<"--------------"<<endl;**/
      //for(int j=1;j<=i;j++)cout<<arr[j]<<" ";cout<<endl;

  }
  ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}


#include<bits/stdc++.h>
const int N=3e5+33;
int a[N];
		using namespace std;
		int main(){

		int n,q;
		int j=1;

		vector<int> b(N);
		cin>>n>>q;
		while (q--){
			int sum=0;
			int t,x;
			cin>>t>>x;
			if(t==1)
		{	b[j++]=x ;
			a[x]++;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n";}
			else if(t==2)
		{	a[x]= 0;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n" ; }
			else
		{	{for(int i=1;i<=x;i++)
			if(a[b[i]]>0)
			{a[b[i]]--;}
	          	}
				for(int i=1;i<=n;i++)
				sum+= a[i];
				cout<< sum<< "\n";}

			return 0;
		}


#include<bits/stdc++.h>
		using namespace std;
		int main(){

		int n,q;
		int j=1;
		int a[n +1];

		vector<int> b(q+1);
		cin>>n>>q;
		while (q--){
			int sum=0;
			int t,x;
			cin>>t>>x;
			if(t==1)
			b[j++]=x ;
			a[x]++;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<< sum;
			else if(t==2)
			a[x]= 0;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum ;
			else
			for(int i=1;i<=x;i++)
			a[b[i]]--;
				for(int i=1;i<=n;i++)
				sum+= a[i];
				cout<< sum;
			}
			return 0;
		}


#include<bits/stdc++.h>
const int N=3e5+33;
int a[N];
		using namespace std;
		int main(){

		int n,q;
		int j=1;

		vector<int> b(N);
		cin>>n>>q;
		while (q--){
			int sum=0;
			int t,x;
			cin>>t>>x;
			if(t==1)
		{	b[j++]=x ;
			a[x]++;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n";}
			 if(t==2)
		{	a[x]= 0;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n" ; }
			if(t==3)
			{for(int i=1;i<=x;i++)
			if(a[b[i]]>0)
			{a[b[i]]--;}}

				for(int i=1;i<=n;i++)
				sum+= a[i];
				cout<< sum<< "\n";

		}
			return 0;
		}


#include<bits/stdc++.h>
		using namespace std;
		int main(){

		int n,q;
		int j=1;
		int a[n +1];

		vector<int> b(q+1);
		cin>>n>>q;
		while (q--){
			int sum=0;
			int t,x;
			cin>>t>>x;
			if(t==1)
		{	b[j++]=x ;
			a[x]++;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<< sum<<"\n";}
			else if(t==2)
		{	a[x]= 0;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n" ; }
			else
			{for(int i=1;i<=x;i++)
			a[b[i]]--;
				for(int i=1;i<=n;i++)
				sum+= a[i];
				cout<< sum<< "\n";
			}
		}
			return 0;
		}


#include<bits/stdc++.h>
		using namespace std;
		int main(){

		int n,q;
		int j=1;
		int a[n +1];

		vector<int> b(q+1);
		cin>>n>>q;
		while (q--){
			int sum=0;
			int t,x;
			cin>>t>>x;
			if(t==1)
		{	b[j++]=x ;
			a[x]++;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<< sum;}
			else if(t==2)
		{	a[x]= 0;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum ; }
			else
			{for(int i=1;i<=x;i++)
			a[b[i]]--;
				for(int i=1;i<=n;i++)
				sum+= a[i];
				cout<< sum;
			}
		}
			return 0;
		}


#include<bits/stdc++.h>
		using namespace std;
		int main(){

		int n,q;
		int j=1;
		int a[n +1];

		vector<int> b(3e5+33);
		cin>>n>>q;
		while (q--){
			int sum=0;
			int t,x;
			cin>>t>>x;
			if(t==1)
		{	b[j++]=x ;
			a[x]++;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<< sum<<"\n";}
			else if(t==2)
		{	a[x]= 0;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n" ; }
			else
		{	{for(int i=1;i<=x;i++)
			if(a[b[i]]>0)
			{a[b[i]]--;}
			else
			continue;}
				for(int i=1;i<=n;i++)
				sum+= a[i];
				cout<< sum<< "\n";}
			}
		}
			return 0;
		}


#include<bits/stdc++.h>
const int N=3e5+33;
int a[N];
		using namespace std;
		int main(){

		int n,q;
		int j=1;

		vector<int> b(N);
		cin>>n>>q;
		while (q--){
			int sum=0;
			int t,x;
			cin>>t>>x;
			if(t==1)
		{	b[j++]=x ;
			a[x]++;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n";}
			 if(t==2)
		{	a[x]= 0;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n" ; }
			if(t==3)
		{	{for(int i=1;i<=x;i++)
			if(a[b[i]]>0)
			{ --a[b[i]];}}

				for(int i=1;i<=n;i++)
				sum+= a[i];
				cout<< sum<< "\n";}

		}
			return 0;
		}


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

	  queue <int > q[300005];
	  set<int> s;
	  int main(){
	  	int n, a, cnt=1 ;
	  	cin>>n>>a ;
	  	while(a--){
	  		int t,x ;
	  		cin>>t>>x;
	  		if(t==1)
	  		{
	  			q[x].push(cnt) ;
	  			s.insert(cnt) ;
	  			cnt++ ;
			  }
			  else if(t==2){
			  	while(!q[x].empty()){
			  		int r=q[x].front();
			  		q[x].pop() ;
			  		if(s.find(r)!=s.end())
			  		s.erase(r);
				  }
			  }
			  else
			  {
			  	while(!s.empty() && *s.begin()<=x)
			  	s.erase(s.begin());
			  }
			  cout<< s.size() <<"\n" ;

		  }
	  }


#include<bits/stdc++.h>
const int N=3e5+33;
		using namespace std;
		int main(){

		int n,q;
		int j=1;
		int a[N];

		vector<int> b(3e5+33);
		cin>>n>>q;
		while (q--){
			int sum=0;
			int t,x;
			cin>>t>>x;
			if(t==1)
		{	b[j++]=x ;
			a[x]++;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<< sum<<"\n";}
			else if(t==2)
		{	a[x]= 0;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n" ; }
			else
		{	{for(int i=1;i<=x;i++)
			if(a[b[i]]>0)
			{a[b[i]]--;}
			else
			continue;}
				for(int i=1;i<=n;i++)
				sum+= a[i];
				cout<< sum<< "\n";}
			}

			return 0;
		}


#include<bits/stdc++.h>
const int N=3e5+33;
int a[N];
		using namespace std;
		int main(){

		int n,q;
		int j=1;

		vector<int> b(N);
		cin>>n>>q;
		while (q--){
			int sum=0;
			int t,x;
			cin>>t>>x;
			if(t==1)
		{	b[j++]=x ;
			a[x]++;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n";}
			else if(t==2)
		{	a[x]= 0;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n" ; }
			else
		{	{for(int i=1;i<=x;i++)
			if(a[b[i]]>0)
			{a[b[i]]--;}
	          	}
				for(int i=1;i<=n;i++)
				sum+= a[i];
				cout<< sum<< "\n";}

		}

			return 0;
		}


#include<bits/stdc++.h>
		using namespace std;
		int main(){

		int n,q;
		int j=1;
		vector<int> a[n +1];
		memset(a,0, a.size());
		vector<int> b(q+1);
		cin>>n>>q;
		while (q--){
			int sum=0;
			int t,x;
			cin>>t>>x;
			if(t==1)
			b[j++]=x ;
			a[x]++;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<< sum;
			else if(t==2)
			a[x]= 0;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum ;
			else
			for(int i=1;i<=x;i++)
			a[b[i]]--;
				for(int i=1;i<=n;i++)
				sum+= a[i];
				cout<< sum;
			}
			return 0;
		}


#include<bits/stdc++.h>
		using namespace std;
		int main(){

		int n,q;
		int j=1;
		int a[n +1];

		vector<int> b(3e5+33);
		cin>>n>>q;
		while (q--){
			int sum=0;
			int t,x;
			cin>>t>>x;
			if(t==1)
		{	b[j++]=x ;
			a[x]++;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<< sum<<"\n";}
			else if(t==2)
		{	a[x]= 0;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n" ; }
			else
		{	{for(int i=1;i<=x;i++)
			if(a[b[i]]>0)
			{a[b[i]]--;}
			else
			continue;}
				for(int i=1;i<=n;i++)
				sum+= a[i];
				cout<< sum<< "\n";}
			}

			return 0;
		}


#include<bits/stdc++.h>
const int N=3e5+33;
int a[N];
		using namespace std;
		int main(){

		int n,q;
		int j=1;

		vector<int> b(N);
		cin>>n>>q;
		while (q--){
			int sum=0;
			int t,x;
			cin>>t>>x;
			if(t==1)
		{	b[j++]=x ;
			a[x]++;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n";}
			else if(t==2)
		{	a[x]= 0;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum<<"\n" ; }
			else
		{	{for(int i=1;i<=x;i++)
			if(a[b[i]]>0)
			{a[b[i]]--;}
			else
			continue;}
				for(int i=1;i<=n;i++)
				sum+= a[i];
				cout<< sum<< "\n";}
			}

			return 0;
		}


	#include<bits/stdc++.h>
		using namespace std;
		int main(){

		int n,q;
		int j=1;
		vector<int> a[n];
		vector<int> b(q+1);
		cin>>n>>q;
		while (q--){
			int sum=0;
			cin>>t>>x;
			if(t==1)
			b[j++]=x ;
			a[x]++;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<< sum;
			else if(t==2)
			a[x]= 0;
			for(int i=1;i<=n;i++)
			sum+= a[i];
			cout<<sum ;
			else
			for(int i=1;i<=x;i++)
			a[b[i]]--;
				for(int i=1;i<=n;i++)
				sum+= a[i];
				cout<< sum;
			}
			return 0;
		}


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

	  queue <int > q[300005];
	  set<int> s;
	  int main(){
	  	int n, a, cnt=1 ;
	  	cin>>n>>a ;
	  	while(a--){
	  		int t,x ;
	  		cin>>t>>x;
	  		if(t==1)
	  		{
	  			q[x].push(cnt) ;
	  			s.insert(cnt) ;
	  			cnt++ ;
			  }
			  else if(t==2){
			  	while(!q[x].empty()){
			  		int r=q[x].front();
			  		q[x].pop() ;
			  		if(s.find(r)!=s.end())
			  		s.erase(r);
				  }
			  }
			  else
			  {
			  	while(!s.empty && *s.begin()<=x)
			  	s.erase(s.begin());
			  }
			  cout<< s.size() <<"\n" ;

		  }
	  }


#include<iostream>
using namespace std;
#define max(a,b) a>b?a:b
int passenger[1005];
int main()
{
	int n, s;
	cin >> n >> s;
	int fi,ti;
	for (int i = 0; i < n; i++)
	{
		cin >> fi >> ti;
		passenger[fi] = max(passenger[fi], ti);
	}
	int ret = 0;
	for (int i = s; i > 0; i--)
	{
		if (passenger[i] != 0)
		{
			if (passenger[i] >= ret)
			{
				ret = passenger[i];
				ret++;
			}
			else
			{
				ret++;
			}
		}
		else
		{
			ret++;
		}
	}
	cout << ret << endl;

	return 0;
}


#include<iostream>
using namespace std;
#define max(a,b) a>b?a:b
int passenger[1005];
int main()
{
	int n, s;
	cin >> n >> s;
	int fi,ti;
	for (int i = 0; i < n; i++)
	{
		cin >> fi >> ti;
		passenger[fi] = max(passenger[fi], ti);
	}
	int ret = 0;
	for (int i = s; i >= 0; i--)
	{
		if (passenger[i] != 0)
		{
			if (passenger[i] >= ret)
			{
				ret = passenger[i];
			}
			else
			{
				ret++;
			}
		}
		else
		{
			ret++;
		}
	}
	cout << ret << endl;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>

using namespace std;
int n, s;
int t[10001], f[10001];
int main ()
{
    cin >> n>>s;
    for (int i =0; i<n; i++)
    {
        cin>>f[i]>>t[i];
    }
    int rez = 0;
    int temp =0;
    for (int i =s; i>0; i--)
    {
            int maxt=0;
            for (int j=0; j<n; j++)
            {
                if (f[j]==i)
                {
                    if (maxt<t[j]) maxt = t[j];
                }

            }
            if (maxt>rez)
            {
                rez+=maxt-rez;
                rez++;
            }
            else
            {
                rez++;
            }

        }

    cout << rez;
    }


#include <iostream>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>

using namespace std;
int n, s;
int t[10001], f[10001];
int main ()
{
    cin >> n>>s;
    for (int i =0; i<n; i++)
    {
        cin>>f[i]>>t[i];
    }
    int rez = 0;
    int temp =0;
    for (int i =s; i>0; i--)
    {
        if (i==s)
        {
        int maxt=0;
        for (int j=0; j<n; j++)
        {
            if (f[j]==s)
            {
                if (maxt<t[j]) maxt = t[j];
            }
        }
        rez+=1+maxt;
            temp = maxt;
        }
        else

        {
            int maxt=0;
            for (int j=0; j<n; j++)
            {
                if (f[j]==i)
                {
                    if (maxt<t[j]) maxt = t[j];
                }

            }
            if (maxt>rez)
            {
                rez+=maxt-rez;
            }
            else
            {
                rez++;
            }

        }

        }
    cout << rez+1;
    }


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
///////////////////////////
struct fl
{
    int f;
    int t;
};
bool operator <(fl a,fl b)
{
    if(b.t <= a.t) return 1;
    else return 0;
    return 0;
}

int i,ans,n,s,t,d;
fl m[100];

int main()
{
    scanf("%d%d",&n,&s);
    for(i = 1;i <= n;i++)
        scanf("%d%d",&m[i].f,&m[i].t);
    m[0].f = s;
    m[0].t = 0;
    sort(m,m+n+1);

    ans = m[0].t + m[0].f;
    if(s - m[0].f > m[0].t) ans = s;
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
///////////////////////////
struct fl
{
    int f;
    int t;
};
bool operator <(fl a,fl b)
{
    if(b.t < a.t) return 1;
    else if(b.t == a.t)
    {
        if(b.f < a.f) return 1;
    }
    return 0;
}

int i,ans,n,s,t,d;
fl m[100];
int m1[100];
int main()
{
    scanf("%d%d",&n,&s);
    for(i = 0;i < n;i++)
        scanf("%d%d",&m[i].f,&m[i].t);

    sort(m,m+n);

    for(i = 0;i < n;i++)
        m1[i] = m[i].f+m[i].t;
    sort(m1,m1+n);
    if(s - m[0].f > m1[n-1]) ans = s;
    else ans = m1[n-1];
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
///////////////////////////
struct fl
{
    int f;
    int t;
};
bool operator <(fl a,fl b)
{
    if(b.t < a.t) return 1;
    else if(b.t == a.t)
    {
        if(b.f < a.f) return 1;
    }
    return 0;
}

int i,ans,n,s,t,d;
fl m[100];
int m1[100];
int main()
{
    scanf("%d%d",&n,&s);
    for(i = 0;i < n;i++)
        scanf("%d%d",&m[i].f,&m[i].t);

    sort(m,m+n);

    for(i = 0;i < n;i++)
        m1[i] = m[i].f+m[i].t;
    sort(m1,m1+n);
    if(s  > m1[n-1]) ans = s;
    else ans = m1[n-1];
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
///////////////////////////
struct fl
{
    int f;
    int t;
};
bool operator <(fl a,fl b)
{
    if(b.t <= a.t) return 1;
    else return 0;
    return 0;
}

int i,ans,n,s,t,d;
fl m[100];

int main()
{
    scanf("%d%d",&n,&s);
    for(i = 1;i <= n;i++)
        scanf("%d%d",&m[i].f,&m[i].t);
    m[0].f = s;
    m[0].t = 0;
    sort(m,m+n+1);
    ans = m[0].t + m[0].f;
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
///////////////////////////
struct fl
{
    int f;
    int t;
};
bool operator <(fl a,fl b)
{
    if(b.t < a.t) return 1;
    return 0;
}

int i,ans,n,s,t,d;
fl m[100];

int main()
{
    scanf("%d%d",&n,&s);
    for(i = 0;i < n;i++)
        scanf("%d%d",&m[i].f,&m[i].t);

    sort(m,m+n);

    ans = m[0].t + m[0].f;
    if(s - m[0].f > m[0].t) ans = s;
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
///////////////////////////
struct fl
{
    int f;
    int t;
};
bool operator <(fl a,fl b)
{
    if(b.t < a.t) return 1;
    else if(b.t == a.t)
    {
        if(b.f < a.f) return 1;
    }
    return 0;
}

int i,ans,n,s,t,d;
fl m[100];

int main()
{
    scanf("%d%d",&n,&s);
    for(i = 0;i < n;i++)
        scanf("%d%d",&m[i].f,&m[i].t);

    sort(m,m+n);

    ans = m[0].t + m[0].f;
    if(s - m[0].f > m[0].t) ans = s;
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
///////////////////////////
struct fl
{
    int f;
    int t;
};
bool operator <(fl a,fl b)
{
    if(b.t < a.t) return 1;
    else if(b.t == a.t)
    {
        if(b.f < a.f) return 1;
    }
    return 0;
}

int i,ans,n,s,t,d;
fl m[100];
int m1[100];
int main()
{
    scanf("%d%d",&n,&s);
    for(i = 0;i < n;i++)
        scanf("%d%d",&m[i].f,&m[i].t);

    sort(m,m+n);

    for(i = 0;i < n;i++)
        m1[i] = m[i].f+m[i].t;
    sort(m1,m1+n);
    if(s - m[0].f > m1[0]) ans = s;
    else ans = m1[0];
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
///////////////////////////
struct fl
{
    int f;
    int t;
};
bool operator <(fl a,fl b)
{
    if(a.f > b.f) return 1;
    else if(a.f == b.f)
    {
        if(a.t < b.t) return 1;
        else           return 0;
    }
    return 0;
}

int i,ans,n,s,t,d;
fl m[100];

int main()
{
    scanf("%d%d",&n,&s);
    for(i = 1;i <= n;i++)
        scanf("%d%d",&m[i].f,&m[i].t);
    m[0].f = s;
    m[0].t = 0;
    sort(m,m+n+1);
    for(i = 1;i <= n;i++)
    {
        d = t;
        t += m[i-1].f - m[i].f;
        if(m[i].t > t) t += m[i].t - t;
        ans += t - d;
    }
    if( m[n].f != 0) ans += m[n].f;
    if(n == 1) ans += m[0].t;
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
///////////////////////////
struct fl
{
    int f;
    int t;
};
bool operator <(fl a,fl b)
{
    if(b.t < a.t) return 1;
    else if(b.t == a.t)
    {
        if(b.f < a.f) return 1;
    }
    return 0;
}

int i,ans,n,s,t,d;
fl m[100];
int m1[100];
int main()
{
    scanf("%d%d",&n,&s);
    for(i = 0;i < n;i++)
        scanf("%d%d",&m[i].f,&m[i].t);

    sort(m,m+n);

    for(i = 0;i < n;i++)
        m1[i] = m[i].f+m[i].t;
    sort(m1,m1+n);
    printf("%d\n",m1[0]);
    if(s - m[0].f > m1[0]) ans = s;
    else ans = m1[0];
    printf("%d",ans);
    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
    int n,s,totalseconds=0;
    cin>>n>>s;
    vector<pair<int, int>>floors(n);
    for (int i=0; i<n; i++) {
        cin>>floors[i].first>>floors[i].second;
    }
    sort(floors.begin(), floors.end());
    for (int i=n-1; i>=0; i--) {
        if (i==n-1) {
            totalseconds+=s-floors[i].first;
        }
        else{
            totalseconds+=floors[i+1].first-floors[i].first;
        }
        floors[i].second-=totalseconds;
        if (floors[i].second<0) {
            floors[i].second=0;
        }
        totalseconds+=floors[i].second;
    }
    if (n>=1) {
        totalseconds+=floors[0].first;
    }
    else if (n==0){
        totalseconds+=s;
    }
    cout<<totalseconds<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <math.h>
using namespace std;
int main(){
    int n,s,totalseconds=0;
    cin>>n>>s;
    vector<pair<int, int>>floors(n);
    for (int i=0; i<n; i++) {
        cin>>floors[i].first>>floors[i].second;
    }
    sort(floors.begin(), floors.end());
    for (int i=n-1; i>=0; i--) {
        if (i==n-1) {
            totalseconds+=s-floors[i].first;
        }
        else{
            totalseconds+=floors[i+1].first-floors[i].first;
        }
        floors[i].second-=totalseconds;
        if (floors[i].second<0) {
            floors[i].second=0;
        }
        totalseconds+=floors[i].second;
    }
    if (n>=1) {
        totalseconds+=floors[0].first;
    }
    else if (n==0){
        totalseconds+=s;
    }
    cout<<totalseconds<<endl;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <crtdbg.h>
#include <ctype.h>
#include <math.h>

#define min(a,b) (((a)<(b)) ? (a) : (b))
#define max(a,b) (((a)>(b)) ? (a) : (b))

int compare(const void * x1, const void * x2)
{
	return (*(int*)x1 - *(int*)x2);
}

int main(void)
{
	//freopen("symposium.in", "r", stdin);
	//freopen("symposium.out", "w", stdout);
	int n, s, f[100], t[100], ans = 0;
	scanf("%d %d", &n, &s);
	for (int i = 0; i < n; i++)
	{
		scanf("%d %d", &f[i], &t[i]);
	}
	for (int i = 0; i < n - 1; i++)
	{
		for (int j = 0; j < n - i - 1; j++)
		{
			if (f[j] < f[j + 1])
			{
				int tmp = f[j];
				f[j] = f[j + 1];
				f[j + 1] = tmp;
				tmp = t[j];
				t[j] = t[j + 1];
				t[j + 1] = tmp;
			}
		}
	}
	for (int i = 0; i < n; i++)
	{
		ans += s - f[i];
		s = f[i];
		ans += max(t[i] - ans, 0);
	}
	ans += s;
	printf("%d\n", ans);
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <climits>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <algorithm>
using namespace std;

#define mod 1000000007
#define N 103

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

struct node{
	int floor,arrivalTime;
};
node A[N];
bool comparefn(node a, node b){
	return a.floor > b.floor;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
#ifdef _DEBUG
	freopen("ip.txt","r",stdin);
	//freopen("op.txt","w",stdout);
#endif
	int n,s;
	cin>>n>>s;
	for(int i = 0;i < n;i++)
		cin>>A[i].floor>>A[i].arrivalTime;
	sort(A,A+n,comparefn);
	int ans = 0;
	for(int i = 0;i < n;i++){
		if(i == 0)
			ans = s - A[i].floor;
		else
			ans += A[i-1].floor - A[i].floor;
		if(A[i].arrivalTime > ans)
			ans = A[i].arrivalTime;
	}
	ans += A[n-1].floor;
	cout<<ans<<"\n";

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <climits>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <algorithm>
using namespace std;

#define mod 1000000007
#define M  200005

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
#ifdef _DEBUG
	freopen("ip.txt","r",stdin);
	//freopen("op.txt","w",stdout);
#endif
	int n,s;
	cin>>n>>s;
	int max_floor = INT_MIN, max_time = INT_MIN, floor_maxtime = 0,ans = 0;
	for(int i = 0; i < n; i++){
		int f,t;
		cin>>f>>t;
		if(max_floor < f)
			max_floor = f;
		if(max_time < t){
			max_time = t;
			floor_maxtime = f;
		}
	}
	if(s-max_floor >  max_time)
		ans = s;
	else
		ans = max_time+floor_maxtime;
	cout<<ans<<"\n";
	return 0;

}


#include <iostream>
#include <fstream>
#include <sstream>
#include <limits>

#include<cstdlib>
#include <cmath>
#include <algorithm>

#include <string>
#include <vector>
#include <map>
#include<set>
#include <queue>

using namespace std;

#define int long long
#define fi(i, a, b) for(int i = (a); (i) < (b); (i)++)

const int N = 100001;
pair<int, int> a[N];
void main()
{
#if defined(DEBUG) || defined(_DEBUG)
  ifstream cin("input.txt");
  ofstream cout("output.txt");
#endif
  int n,s;
  cin >> n >> s; int best = 0;
  fi(i, 0, n){
	  int x, y; cin >> x >> y; a[i] = make_pair(x,y);

  }
  sort(a, a + n);
  int cur = s;
  for(int i = n-1; i>=0; i--){
	  best = max(best + s - a[i].first, a[i].second);
	  s = a[i].first;
  }
  cout << best+a[0].first;
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <limits>

#include<cstdlib>
#include <cmath>
#include <algorithm>

#include <string>
#include <vector>
#include <map>
#include<set>
#include <queue>

using namespace std;

#define int long long
#define fi(i, a, b) for(int i = (a); (i) < (b); (i)++)

const int N = 100001;

void main()
{
#if defined(DEBUG) || defined(_DEBUG)
  ifstream cin("input.txt");
  ofstream cout("output.txt");
#endif
  int n,s;
  cin >> n >> s; int best = -1;
  fi(i, 0, n){
      int x, y; cin >> x >> y;
      best = max(best, x + y);
  }
  cout << best;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
          int n = 0, m = 0, c = 0, d = 0, t = 0;
          cin >> n >> m;
          if (n == 1)
          {
                    cin >> n >> n >> m;
                    cout << n + m;
                    return 0;
          }
          vector<int> a;
          vector<int> b;
          for (int i = 0; i < n; i++)
          {
                    cin >> c >> d;
                    a.push_back(c);
                    b.push_back(d);
          }
          if (a[n - 1] != m)
          {
                    a.push_back(m);
                    b.push_back(0);
          }
          n--;
          c = n;
          while (c > -1)
          {
                    if (t < b[c])
                    {
                              t = b[c];
                              if (c < n)
                              {
                                        t += a[c + 1] - a[c];
                              }
                    }
                    c--;
          }
          cout << t + 1;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
          int n = 0, m = 0, c = 0, d = 0, t = 0;
          cin >> n >> m;
          vector<int> a;
          vector<int> b;
          for (int i = 0; i < n; i++)
          {
                    cin >> c >> d;
                    a.push_back(c);
                    b.push_back(d);
          }
          if (a[n - 1] != m)
          {
                    a.push_back(m);
                    b.push_back(0);
                    n++;
          }
          n--;
          c = n;
          while (n > -1)
          {
                    if (c > n)
                    {
                              t += a[n + 1] - a[n];
                    }
                    if (t <= b[n])
                    {
                              t = b[n];
                    }
                    n--;
          }
          cout << t + a[0];
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
          int n = 0, m = 0, c = 0, d = 0, t = 0;
          cin >> n >> m;
          vector<int> a;
          vector<int> b;
          for (int i = 0; i < n; i++)
          {
                    cin >> c >> d;
                    a.push_back(c);
                    b.push_back(d);
          }
          if (a[n - 1] != m)
          {
                    a.push_back(m);
                    b.push_back(0);
          }
          n--;
          c = n;
          while (c > -1)
          {
                    if (t < b[c])
                    {
                              t = b[c];
                              if (c < n)
                              {
                                        t += a[c + 1] - a[c];
                              }
                    }
                    c--;
          }
          cout << t + 1;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
pair<int,int> a[1010];
int main()
{
 int n, m;
 cin >> n >> m;
 for (int i = 0; i < n; i++)
 {
  cin >> a[i].first >> a[i].second;
 }
 sort(a, a + n);
 int now = 0;
 int i = m - 1;
 int k = n - 1;
 int last = m ;
 for (int i = n-1; i >=0; i--)
 {
  now+= (last - a[i].first);
  now=(a[i].second > now ? a[i].second : now);
  last = a[i].first;

 }
 now += last;
 cout << now;
 return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
pair<int,int> a[1010];
int main()
{
 int n, m;
 cin >> n >> m;
 for (int i = 0; i < n; i++)
 {
  cin >> a[i].first >> a[i].second;
 }
 sort(a, a + n);
 int now = 0;
 int i = m - 1;
 int k = n - 1;
 int last = m ;
 for (int i = n-1; i >=0; i--)
 {
  now+= (last - a[i].first);
  now=(a[i].second > now ? a[i].second : now);
  last = a[i].first;

 }
 now += last;
 cout << now;
 return 0;
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
pair<int,int> a[1010];
int main()
{
 int n, m;
 cin >> n >> m;
 for (int i = 0; i < n; i++)
 {
  cin >> a[i].first >> a[i].second;
 }
 sort(a, a + n);
 int now = 0;
 int i = m - 1;
 int k = n - 1;
 int last = m ;
 for (int i = n-1; i >=0; i--)
 {
  now+= (last - a[i].first);
  now=(a[i].second > now ? a[i].second : now);
  last = a[i].first;

 }
 now += last;
 cout << now;
 return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

#define DEBUG

using namespace std;

int main() {

    int n,s;
    cin >> n >> s;
    int cur, tur;
    int ans = s;
    for ( int i = 0; i < n; ++i ) {
        cin >> cur >> tur;
        if ( cur + tur > ans ) {
            ans = cur + tur;
        }
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

#define DEBUG

using namespace std;

int main() {
#ifdef DEBUG
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int n,s;
    cin >> n >> s;
    int cur,tur;
    int ans = s;
    for ( int i = 0; i < n; ++i ) {
        cin >> cur >>tur;
        if ( cur + tur > ans ) {
            ans = cur + tur;
        }
    }
    cout << ans;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#pragma warning(disable:4996)
struct data
{
	int f;
	int t;
};
bool cmp(data p1,data p2)
{
	return p1.f > p2.f;
}
using namespace std;
int main()
{
	int n,s;
	vector<data> d;
	while(scanf("%d %d",&n,&s) == 2)
	{
		data p;
		p.f = 0;
		p.t = 0;
		d.push_back(p);
		for(int i = 0 ; i < n ; ++i){
			scanf("%d %d",&p.f,&p.t);
			d.push_back(p);
		}
		sort(d.begin(),d.end(),cmp);
		int time = 0;
		int f = s;
		int delta = 0;
		int temp = 0;
		for(vector<data>::iterator it = d.begin();it != d.end() ; ++it)
		{
			delta = f - it->f;
			f = it->f;
			if(it->t <= 0){}
			else it->t -= delta;
			time += delta + it->t;
			temp = delta + it->t;
			//printf("%d %d %d\n",delta,time,f);
			for(vector<data>::iterator j = it;j != d.end() ; ++j)
			{
				j->t -= temp;
				if(j->t < 0) j->t = 0;
			}
		}
		printf("%d\n",time);
	}
}


#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#pragma warning(disable:4996)
struct data
{
	int f;
	int t;
};
bool cmp(data p1,data p2)
{
	return p1.f > p2.f;
}
using namespace std;
int main()
{
	int n,s;
	vector<data> d;
	while(scanf("%d %d",&n,&s) == 2)
	{
		data p;
		p.f = 0;
		p.t = 0;
		d.push_back(p);
		for(int i = 0 ; i < n ; ++i){
			scanf("%d %d",&p.f,&p.t);
			d.push_back(p);
		}
		sort(d.begin(),d.end(),cmp);
		int time = 0;
		int f = s;
		int delta = 0;
		int temp = 0;
		for(vector<data>::iterator it = d.begin();it != d.end() ; ++it)
		{
			delta = f - it->f;
			f = it->f;
			if(it->t > 0)
			{
				it->t -= delta;
				if(it->t < 0) it->t = 0;
			}
			time += delta + it->t;
			temp = delta + it->t;
			//printf("%d %d %d\n",delta,time,f);
			for(vector<data>::iterator j = it;j != d.end() ; ++j)
			{
				j->t -= temp;
				if(j->t < 0) j->t = 0;
			}
		}
		printf("%d\n",time);
	}
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <string>
#include <string.h>
#include <math.h>
#include <fstream>
using namespace std;
#define double long double
#define re return
#define LL long long
#define EPS2 0.000000000001
#define EPS1 0.00000000000000001
#define MOD 1000000007
#define INF 1000000000000000000LL
#define N 100000
typedef struct{
	LL f, t;
}ta;

int n, s;
ta all[N];
int main()
{
#ifdef _DINARISIO
	ifstream cin("A.in");
	ofstream cout("A.out");
#endif
	cin >> n >> s;
	LL res = -1;
	for (int i = 0; i < n; ++i){
		cin >> all[i].f>> all[i].t;
		if (res == -1 || all[i].f + all[i].t > res){
			res = all[i].f + all[i].t;
		}
	}
	cout << res;
	re 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <string>
#include <string.h>
#include <math.h>
#include <fstream>
using namespace std;
#define double long double
#define re return
#define LL long long
#define EPS2 0.000000000001
#define EPS1 0.00000000000000001
#define MOD 1000000007
#define INF 1000000000000000000LL
#define N 100000
typedef struct{
	LL f, t;
}ta;

int n, s;
ta all[N];
int main()
{
#ifdef _DINARISIO
	ifstream cin("A.in");
	ofstream cout("A.out");
#endif
	cin >> n >> s;
	LL res = -1;
	for (int i = 0; i < n; ++i){
		cin >> all[i].f>> all[i].t;
		LL need = s - all[i].f;
		if (need > all[i].t)all[i].t = need;
		if (res == -1 || all[i].f + all[i].t > res){
			res = all[i].f + all[i].t;
		}
	}
	cout << res;
	re 0;
}


#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <set>
#include <vector>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <climits>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
#define INF 0X3f3f3f3f
const ll MAXN = 1e3+ 7;
const ll MOD = 1e9 + 7;
struct node
{
    int h,t;
}a[MAXN];
bool cmp(node x,node y)
{
    if(x.h==y.h)
        return x.t<y.t;
    return x.h>y.h;
}
int main()
{
    ios::sync_with_stdio(false);
    int n,s;
    cin>>n>>s;
    for(int i=0;i<n;i++)
    cin>>a[i].h>>a[i].t;
    sort(a,a+n,cmp);
    int tot=0,tm=0;
    for(int i=0;i<n;i++)
    {
        tot+=(s-a[i].h);
        tm+=(s-a[i].h);
        s=a[i].h;
        if(tm<a[i].t)
        tm=a[i].t;
    }
    cout<<tm+s<<endl;
    // system("pause");
    return 0;
}


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

int main() {
	map<int, int> pairs;
	int n, s, time, level;

	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		cin >> level >> time;
		pairs[time] = level;
	}

	cout << pairs.rbegin()->first + pairs.rbegin()->second;
	cin >> n;

	return 0;
}


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

int main() {
	int table[1000] = { -1 }; for (int i = 0; i < 1000; i++) table[i] = -1;
	int n, s, time, level;

	cin >> n >> s;

	for (int i = 0; i < n; i++) {
		cin >> level >> time;
		if (table[level] < time) table[level] = time;
	}

	time = 0;
	level = s;

	while (level > 0) {
		if (table[level] == -1) {
			time++;
			level--;
			continue;
		}
		if (table[level] > time) {
			time++;
			continue;
		}
		if (table[level] <= time) {
			time++;
			level--;
		}
	}

	cout << time;

	return 0;
}


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

int main() {
	set<pair<int,int>> pairs;
	int n, s, time, level;

	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		cin >> level >> time;
		pairs.insert(make_pair(time, level));
	}

	cout << pairs.rbegin()->first + pairs.rbegin()->second;
	cin >> n;

	return 0;
}


# include <iostream>
# include <set>
# include <algorithm>
using namespace std;

int main() {
	set<pair<int, int>> table;
	int n, s, time, level;

	cin >> n >> s;

	for (int i = 0; i < n; i++) {
		cin >> level >> time;
		table.insert(make_pair(level,time));
	}

	table.insert(make_pair(0, 0));

	time = 0;
	level = s;

	for (set<pair<int, int>>::reverse_iterator it = table.rbegin(); it != table.rend(); it++) {
		if (it->first != level) {
			time += abs(it->first - level);
			level = it->first;
		}
		if (time < it->second) {
			time += abs(it->second - time);
		}
	}

	cout << time;

	return 0;
}


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

int main() {
	int table[1000] = { -1 }; for (int i = 0; i < 1000; i++) table[i] = -1;
	int n, s, time, level;

	cin >> n >> s;

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

	time = 0;
	level = s;

	while (level >= 0) {
		if (table[level] == -1) {
			time++;
			level--;
			continue;
		}
		if (table[level] > time) {
			time++;
			continue;
		}
		if (table[level] <= time) {
			time++;
			level--;
		}
	}

	cout << time-1;

	return 0;
}


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

int main() {
	int table[1000] = { -1 }; for (int i = 0; i < 1000; i++) table[i] = -1;
	int n, s, time, level;

	cin >> n >> s;

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

	time = 0;
	level = s;

	while (level > 0) {
		if (table[level] == -1) {
			time++;
			level--;
			continue;
		}
		if (table[level] > time) {
			time++;
			continue;
		}
		if (table[level] <= time) {
			time++;
			level--;
		}
	}

	cout << time;

	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;

struct abc
{
    int f,t;
};
abc p[1005];

bool cmp(abc a,abc b)
{
    if(a.f!=b.f)
        return a.f>b.f;
    return a.t<b.t;
}

int main()
{
    int i,j,ans;
    int n,s;
    while(~scanf("%d%d",&n,&s))
    {
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&p[i].f,&p[i].t);
        }
        sort(p,p+n,cmp);
        ans=p[0].f;
        if(ans<p[0].t)
            ans=p[0].t;
        for(i=1;i<n;i++)
        {
            ans+=(p[i-1].f-p[i].f);
            if(ans<p[i].t)
                ans+=(p[i].t-ans);
        }
        if(p[n-1].f!=0)
            ans+=p[n-1].f;
        printf("%d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;

struct abc
{
    int f,t;
};
abc p[1005];

bool cmp(abc a,abc b)
{
    if(a.f!=b.f)
        return a.f>b.f;
    return a.t<b.t;
}

int main()
{
    int i,j,ans;
    int n,s;
    while(~scanf("%d%d",&n,&s))
    {
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&p[i].f,&p[i].t);
        }
        sort(p,p+n,cmp);
        ans=s-p[0].f;
        if(ans<p[0].t)
            ans=p[0].t;
        for(i=1;i<n;i++)
        {
            ans+=(p[i-1].f-p[i].f);
            if(ans<p[i].t)
                ans+=(p[i].t-ans);
        }
        if(p[n-1].f!=0)
            ans+=p[n-1].f;
        printf("%d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;

struct abc
{
    int f,t;
};
abc p[1005];

bool cmp(abc a,abc b)
{
    if(a.t!=b.t)
        return a.t>b.t;
    return a.f>b.f;
}

int main()
{
    int i,j,ans;
    int n,s;
    while(~scanf("%d%d",&n,&s));
    {
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&p[i].f,&p[i].t);
        }
        sort(p,p+n,cmp);
        ans=p[i].t+p[i].f;
        printf("%d\n",ans);
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include<cctype>
#include<algorithm>
#include<queue>
#include<stack>
#include<utility>
using namespace std;

int main()
{

    //freopen("in.txt","r",stdin);
    int n ,  s  , time=0 , t , f ;

    scanf("%d%d" , &n , &s);
    vector<pair<int,int>> v;

    for (int i=0 ; i<n ; ++i)
    {
    scanf("%d%d", &f , &t);
    v.push_back(make_pair(f,t));
    }

    sort(v.begin(), v.end());
    reverse(v.begin(),v.end());

    for(int i=0 ; i<n ; ++i)
         {
            time+=s-v[i].first; //numberOfFloorToBeinNext
            time+=max(0,v[i].second-time);//timeNeddedTpStop
            s=v[i].first;//forThelastfloor }

    time+=s;

    printf("%d\n",time);
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include<cctype>
#include<algorithm>
#include<queue>
#include<stack>
#include<utility>
using namespace std;

int main()
{

    //freopen("in.txt","r",stdin);

    int  n , s , time=0 , t  ,f;
    int pas[1001]={0};

    scanf("%d%d" , &n , &s);

    for (int i=0 ; i<n ;++i)
    {scanf("%d%d", &f , &t);
    pas[f]=t;}

    for (int i=s ; i>0 ; --i)
    {
    if (pas[i]>time) time+=(pas[i]-time);
    time++;

    //cout<<i<<" "<<pas[i]<<" "<<time<<endl;
    }

    cout<<time<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include<cctype>
#include<algorithm>
#include<queue>
#include<stack>
#include<utility>
using namespace std;

int main()
{

    //freopen("in.txt","r",stdin);
    int n ,  s  , time=0 , t , f ;

    cin>>n>>f;
    vector<pair<int,int>> v;

    for (int i=0 ; i<n ; ++i)
    {
    cin>>f>>t;
    v.push_back(make_pair(f,t));
    }

    sort(v.begin(), v.end());
    reverse(v.begin(),v.end());

    for(int i=0 ; i<n ; ++i)
         {
            time+=s-v[i].first; //numberOfFloorToBeinNext
            time+=max(0,v[i].second-time);//timeNeddedTpStop
            s=v[i].first;//forThelastfloor }

    time+=s;

    cout<<time<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include<cctype>
#include<algorithm>
#include<queue>
#include<stack>
#include<utility>
using namespace std;

int main()
{

    //freopen("in.txt","r",stdin);

    int  n , s , time=0 , t  ,f;
    int pas[1001]={0};

    scanf("%d%d" , &n , &s);

    for (int i=0 ; i<n ;++i)
    {scanf("%d%d", &f , &t);
    pas[f]=t;}

    for (int i=s ; i>=0 ; --i)
    {
    if (pas[i]>time) time+=(pas[i]-time);

    else time++;

    }

    cout<<time<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include<cctype>
#include<algorithm>
#include<queue>
#include<stack>
#include<utility>
using namespace std;

int main()
{

    //freopen("in.txt","r",stdin);

    int  n , s , time=0 , t  ,f;
    int pas[1001]={0};

    scanf("%d%d" , &n , &s);

    for (int i=0 ; i<n ;++i)
    {scanf("%d%d", &f , &t);
    pas[f]=t;}

    for (int i=s ; i>=0 ; time++,--i)
    {
    if (pas[i]>time) time+=(pas[i]-time);

// cout<<"test "<<i<<" "<<pas[i]<<" "<<time<<endl;
    }

    cout<<--time<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include<cctype>
#include<algorithm>
#include<queue>
#include<stack>
#include<utility>
using namespace std;

int main()
{

    //freopen("in.txt","r",stdin);
    int n ,  s  , time=0 , t , f ;

    cin>>n>>f;
    vector<pair<int,int>> v;

    for (int i=0 ; i<n ; ++i)
    {
    cin>>f>>t;
    v.push_back(make_pair(f,t));
    }

    sort(v.begin(), v.end());
    reverse(v.begin(),v.end());

    for(int i=0 ; i<n ; ++i)
         {
            time+=s-v[i].first; //numberOfFloorToBeinNext
            time+=max(0,v[i].second-time);//timeNeddedTpStop
            s=v[i].first;//forThelastfloor
    }

    time+=s;

    cout<<time<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include<cctype>
#include<algorithm>
#include<queue>
#include<stack>
#include<utility>
using namespace std;

int main()
{

    //freopen("in.txt","r",stdin);
    int n ,  s  , time=0 , t , f ;

    cin>>n>>f;
    vector<pair<int,int>> v;

    for (int i=0 ; i<n ; ++i)
    {
    cin>>f>>t;
    v.push_back(make_pair(f,t));
    }

    sort(v.begin(), v.end());
    reverse(v.begin(),v.end());

    for(int i=0 ; i<n ; ++i)
         {
            time+=s-v[i].first; //numberOfFloorToBeinNext
            time+=max(0,v[i].second-time);//timeNeddedTpStop
            s=v[i].first;//forThelastfloor }

    time+=s;

    printf("%d\n",time);
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include<cctype>
#include<algorithm>
#include<queue>
#include<stack>
#include<utility>
using namespace std;

int main()
{

    //freopen("in.txt","r",stdin);
    int  n , s , time=0 , t  ,f;
    vector<pair<int , int >> pas;

    scanf("%d%d" , &n , &s);
    for (int i=0 ; i<n ;++i)
    {
    scanf("%d%d", &f , &t);
    pas.push_back(make_pair(f,t));
    }

    sort(pas.begin(),pas.end());

    time=s-(pas[n-1].first);
    s=pas[n-1].first;

    for (int j=n-1 ; j>=0 ; --j)
    {
        if (pas[j].second>time) time+=(pas[j].second-time);

        time++;

    }

    cout<<++time<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include<cctype>
#include<algorithm>
#include<queue>
#include<stack>
#include<utility>
using namespace std;

int main()
{

    //freopen("in.txt","r",stdin);
    int n ,  s  , time=0 , t , f ;

    cin>>n>>s;
    vector<pair<int,int>> v;

    for (int i=0 ; i<n ; ++i)
    {
    cin>>f>>t;
    v.push_back(make_pair(f,t));
    }

    sort(v.begin(), v.end());
    reverse(v.begin(),v.end());

    for(int i=0 ; i<n ; ++i)
         {
            time+=s-v[i].first; //numberOfFloorToBeinNext
            time+=max(0,v[i].second-time);//timeNeddedTpStop
            s=v[i].first;//forThelastfloor
    }

    time+=s;

    cout<<time<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include<cctype>
#include<algorithm>
#include<queue>
#include<stack>
#include<utility>
using namespace std;

int main()
{

    //freopen("in.txt","r",stdin);

    int  n , s , time=0 , t  ,f;
    int pas[1001]={0};

    scanf("%d%d" , &n , &s);

    for (int i=0 ; i<n ;++i)
    {scanf("%d%d", &f , &t);
    pas[f]=max(t,pas[f]);}

    for (int i=s ; i>0 ; --i)
    {
    if (pas[i]>time) time+=(pas[i]-time);
    time++;

    //cout<<i<<" "<<pas[i]<<" "<<time<<endl;
    }

    cout<<time<<endl;
    return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;

int tm[1005];
int main()
{
    int i,j,k;
    int t1,t2;
int m;
    int n;
    cin>>n;
    cin>>m;
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&t1,&t2);
        if (t1+t2>sum) sum=t2+t1;

    }
    printf("%d\n",sum);
    return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;

int tm[1005];
int main()
{
    int i,j,k;
    int t1,t2;
int m;
    int n;
    cin>>n;
    cin>>m;
    int sum=m;
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&t1,&t2);
        tm[t1]=t2;
//      if (t1+t2>sum) sum=t1+t2;
    }
    for (i=1;i<=m;i++)
    {
        if (i+tm[i]>sum) sum=i+tm[i];
    }
    printf("%d\n",sum);
    return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;

int tm[1005];
int main()
{
    int i,j,k;
    int t1,t2;
int m;
    int n;
    cin>>n;
    cin>>m;
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&t1,&t2);
        tm[t1]=t2;
    }
    int sum=m;
    for (i=m;i>=1;i--)
    {
        if (i+tm[i]>sum) sum=i+tm[i];

    }
    printf("%d\n",sum);
    return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;

int tm[1005];
int main()
{
    int i,j,k;
    int t1,t2;
int m;
    int n;
    cin>>n;
    cin>>m;
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&t1,&t2);
        tm[t1]=t2;
    }
    int sum=m;
    for (i=1;i<=m;i++)
    {
        if (i+tm[i]>sum) sum=i+tm[i];
    }
    printf("%d\n",sum);
    return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;

int tm[1005];
int main()
{
    int i,j,k;
    int t1,t2;
int m;
    int n;
    cin>>n;
    cin>>m;
    int sum=m;
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&t1,&t2);
        if (tm[t1]==0)
        tm[t1]=t2;
        else
            if (t2>tm[t1])
                tm[t1]=t2;
    }
    int run=0;
    for (i=m;i>=1;i--)
    {
        if (run<tm[i])
             run+=tm[i]-run+1;
        else
        run++;
    }
    printf("%d\n",run);
    return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;

int tm[1005];
int main()
{
	int i,j,k;
	int t1,t2;
int m;
	int n;
	cin>>n;
	cin>>m;
	for (i=1;i<=n;i++)
	{
		scanf("%d%d",&t1,&t2);
		tm[t1]=t2;
	}
	int run=0;
	for (i=m;i>=0;i--)
	{

		if (run<tm[i])
			 run+=tm[i]-run-1;

		run++;
	}
	printf("%d\n",run);
	return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;

int tm[1005];
int main()
{
    int i,j,k;
    int t1,t2;
int m;
    int n;
    cin>>n;
    cin>>m;
    int sum=m;
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&t1,&t2);
        if (tm[t1]==0)
        tm[t1]=t2;
        else
            if (t2>tm[t1])
                tm[t1]=t2;
//      if (t1+t2>sum) sum=t1+t2;
    }
    for (i=1;i<=m;i++)
    {
        if (i+tm[i]>sum) sum=i+tm[i];
    }
    printf("%d\n",sum);
    return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;

int tm[1005];
int main()
{
    int i,j,k;
    int t1,t2;
int m;
    int n;
    cin>>n;
    cin>>m;
    int sum=m;
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&t1,&t2);
        if (t1+t2>sum) sum=t2+t1;

    }
    printf("%d\n",sum);
    return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;

int tm[1005];
int main()
{
    int i,j,k;
    int t1,t2;
int m;
    int n;
    cin>>n;
    cin>>m;
    int sum=m;
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&t1,&t2);
        tm[t1]=t2;
        if (t1+t2>sum) sum=t1+t2;
    }
    for (i=1;i<=m;i++)
    {
        if (i+tm[i]>sum) sum=i+tm[i];
    }
    printf("%d\n",sum);
    return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;

int tm[1005];
int main()
{
    int i,j,k;
    int t1,t2;
int m;
    int n;
    cin>>n;
    cin>>m;
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&t1,&t2);
        tm[t1]=t2;
    }
    int run=0;
    for (i=m-1;i>=0;i--)
    {
        if (run<tm[i])
             run+=tm[i]-run;
        else
            if (i!=m)
        run++;
    }
    printf("%d\n",run);
    return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;

int tm[1005];
int main()
{
    int i,j,k;
    int t1,t2;
int m;
    int n;
    cin>>n;
    cin>>m;
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&t1,&t2);
        tm[t1]=t2;
    }
    int run=0;
    for (i=m;i>=1;i--)
    {
        if (run<tm[i])
             run+=tm[i]-run+1;
        else
        run++;
    }
    printf("%d\n",run);
    return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;

int tm[1005];
int main()
{
    int i,j,k;
    int t1,t2;
int m;
    int n;
    cin>>n;
    cin>>m;
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&t1,&t2);
        tm[t1]=t2;
    }
    int sum=m;
    for (i=1;i<=m;i++)
    {
        if (i+tm[i]>sum) sum=i+tm[i];

    }
    printf("%d\n",sum);
    return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;

int tm[1005];
int main()
{
    int i,j,k;
    int t1,t2;
int m;
    int n;
    cin>>n;
    cin>>m;
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&t1,&t2);
        tm[t1]=t2;
    }
    int run=0;
    for (i=m;i>=0;i--)
    {
        if (run<tm[i])
             run+=tm[i]-run;
        else if (i!=m)
        run++;
    }
    printf("%d\n",run);
    return 0;

}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
struct Node{
    int x, y;
}e[1005];
int x, s;
int main()
{
    while(scanf("%d%d", &x, &s) != EOF)
    {
        for(int i = 0; i < x; i++)
        {
            scanf("%d%d", &e[i].x, &e[i].y);
        }
        int ans = s - e[x - 1].x;
        for(int i = x - 1; i >= 0; i--)
        {
            if(e[i].y > ans)
                ans = e[i].y;
            if(i != 0)
            {
                ans += (e[i].x - e[i - 1].x);
            }
        }
        ans += e[0].x;
        printf("%d\n", ans);
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long double ld;
typedef long long ll;	// Use "%I64d" as placeholder with printf and scanf.
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef priority_queue<ll, vector<ll>, greater<ll>> min_heap_ll;
typedef priority_queue<ll, vector<ll>, less<ll>> max_heap_ll;

#define pi 3.141592653589793238462643383279502884197169399375105820974944592307816406286
#define f(i, n) for(ll i=0; i<n; ++i)
#define fi(i, n, j) for(ll i=j; i<n; ++i)
#define mp make_pair
#define all(container) container.begin(), container.end()
#define allr(container) container.rbegin(), container.rend()
#define tr(container, it) for (decltype(container.begin()) it = container.begin(); it != container.end(); it++)
#define trr(container, it) for (decltype(container.rbegin()) it = container.rbegin(); it != container.rend(); it++)
#define dist(a, b) sqrtl(powl(ld(a.first - b.first), 2) + powl(ld(a.second - b.second), 2))

// useful functions
ll gcd(ll a, ll b)
{
	return b ? gcd(b, a % b) : a;
}

ll my_exp(ll a, ll b, ll MOD = numeric_limits<ll>::max())
{
	a %= MOD;
	return b ? (((b % 2 == 1 ? a : 1) * my_exp(a * a, b / 2, MOD)) % MOD) : 1;
}

bool is_prime(ll n)	// O(sqrt(n)) implementation check for 0 and 1 separately
{
	if (n != 2 && n % 2 == 0) return false;
	else { for (ll i = 3; (i*i) <= n; i += 2) if (n%i == 0) return false; return true; }
}

// Program global variables

// Program classes and structs

// Program functions

int main()
{
#ifdef _CODE_SOURCE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	double start_time = clock();
#endif
	// Program Code
	ll n, s; cin >> n >> s;
	ll curr = s;
	f(i, n)
	{
		ll f, t; cin >> f >> t;
		curr = max(curr, s + (t - (s - f)));
	}
	cout << curr << endl;

	// Program Code Ends
#ifdef _CODE_SOURCE
	double end_time = clock();
	printf("\nTime = %.3f seconds\n", (end_time - start_time) / CLOCKS_PER_SEC);
#endif
	return(0);
}


#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n, s;
	int m[1001];
	cin >> n >> s;
	for (int i = 0; i < 1001; i++) {
		m[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		int f, t;
		cin >> f >> t;
		m[f] = max(m[f], t);
	}
	int t = 0;
	for (int i = s; i > 0 ; --i) {
		++t;
		t = max(t, m[i]);
	}
	cout << t+1;
	system("pause");
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n, s;
	int m[1001];
	cin >> n >> s;
	for (int i = 0; i < 1001; i++) {
		m[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		int f, t;
		cin >> f >> t;
		m[f] = max(m[f], t);
	}
	int t = 0;
	for (int i = s; i > 0 ; --i) {
		++t;
		t = max(t, m[i]);
	}
	cout << t+1;
	//system("pause");
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n, s;
	int m[1000];
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		int f, t;
		cin >> f >> t;
		m[f] = max(m[f], t);
	}
	int t = 0;
	for (int i = s; i > 0 ; --i) {
		++t;
		t = max(t, m[i]);
	}
	cout << t+1;
	//system("pause");
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n, s;
	int m[1001];
	cin >> n >> s;
	for (int i = 0; i < 1001; i++) {
		m[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		int f, t;
		cin >> f >> t;
		m[f] = max(m[f], t);
	}
	int t = m[s];
	for (int i = s; i > 0 ; --i) {
		++t;
		t = max(t, m[i-1]);
	}
	cout << t;
	//system("pause");
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n, s;
	int m[1001];
	cin >> n >> s;
	for (int i = 0; i < 1001; i++) {
		m[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		int f, t;
		cin >> f >> t;
		m[f] = max(m[f], t);
	}
	int t = 0;
	for (int i = s; i > 0 ; --i) {
		++t;
		t = max(t, m[i]);
	}
	cout << t;
	//system("pause");
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
    int n, s, mx = 1001;
    cin >> n >> s;
    int f[100], t[100];
    for (int i = 0; i < n; i++)
        cin >> f[i] >> t[i];
    int time = 0, k = 0;
    reverse(f + 0, f + n);
    reverse(t + 0, t + n);
    int floor = s;
    for (int i = 0; i < n; i++)
    {
        if (floor != f[i])
        {
            time += (floor - f[i]);
            floor = f[i];
        }
        if (time <= t[i])
            time = t[i];
        else continue;
    }
    time += (f[n-1]);
    cout << time;
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
	int n, s, mx = 1001;
	cin >> n >> s;
	int f[100], t[100];
	for (int i = 0; i < n; i++)
		cin >> f[i] >> t[i];
	int time = 0, k = 0;
	reverse(f + 0, f + n);
	reverse(t + 0, t + n);
	int floor = s;
	for (int i = 0; i < n; i++)
	{
		if (floor != f[i])
		{
			time += (floor - f[i]);
			floor = f[i];
		}
		if (time <= t[i])
			time = t[i];
		else continue;
	}
	cout << time + 2;
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int mb=0,ma=n;
	for (int i=0;i<n;i++){
		int a,b;
		cin>>a>>b;
		if (b==mb && a>ma){
			ma=a;
		}
		if (b>mb){
			mb=b;
			ma=a;
		}
	}
	cout<<ma+mb;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector<int> a(n+1);
	vector<int> t(n);
	for (int i=0;i<n;i++){
		cin>>a[i]>>t[i];
	}
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			if (a[i]>a[j])
			{
				swap(a[i],a[j]);
				swap(t[i],t[j]);
			}
		}
	}
	int r=0;
	int m=0;
	int s=0;
	a[n]=0;
	for (int i=0;i<n;i++){
		if (a[i]==a[i+1]){
			if (t[i]>m){
				m=t[i];
			}
		}
		else{
			r=max(r,r+k-a[i]);
			if (t[i]>m)
				m=t[i];
			s=s+(k-a[i])+max(0,m-r);
			r=max(m,r);
			m=0;
			k=a[i];
		}
	}
	s=s+a[n-1];
	cout<<s;
}


#include <iostream>
void main(){
	long int n, s, f, t, tf[1001] = { 0 }, time = 0;
	scanf_s("%i %i", &n, &s);
	while (n != 0){
		n--;
		scanf_s("%i %i", &f, &t);
		if (t > tf[f])tf[f] = t;
	}
	while (s > 0){
		if (time < tf[s])time += tf[s] - time;
		s--;
		time++;
	}
	printf("%d", time);
}


#include <iostream>
void main(){
	long int n, s, f, t, tf[1001] = { 0 }, time = 0;
	scanf_s("%i %i", &n, &s);
	while (n != 0){
		n--;
		scanf_s("%i %i", &f, &t);
		tf[f] = t;
	}
	while (s > 0){
		if (time < tf[s])time += tf[s] - time;
		s--;
		time++;
	}
	printf("%d", time);
}


#include <iostream>
void main(){
	int n, s, f, t, tf[1001] = { 0 }, time = 0;
	scanf_s("%i %i", &n, &s);
	while (n != 0){
		n--;
		scanf_s("%i %i", &f, &t);
		tf[f] = t;
	}
	while (s > 0){
		if (time < tf[s])time += tf[s] - time;
		s--;
		time++;
	}
	printf("%d", time);
	scanf_s("%i %i", &f, &t);
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define PI 3.14159265358979
#define big 1e9

int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a;
	for (int i = 0; i < n; ++i){
		int t1, t2;
		cin >> t1 >> t2;
		a.push_back(make_pair(t1, t2));
	}
	a.push_back(make_pair(m, 0));
	int time = 0;
	for (int i = n - 1; i >= 0;--i){
		time += a[i + 1].first - a[i].first;
		time = max(time, a[i].second);
	}
	cout << time + a[0].first;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define PI 3.14159265358979
#define big 1e9

int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a;
	for (int i = 0; i < n; ++i){
		int t1, t2;
		cin >> t1 >> t2;
		a.push_back(make_pair(t1, t2));
	}
	a.push_back(make_pair(0, 0));
	int time = 0;
	for (int i = n - 1; i >= 0;--i){
		time += a[i + 1].first - a[i].first;
		time = max(time, a[i].second);
	}
	cout << time + a[0].first;
	return 0;
}


#include <iostream>

using namespace std;

int main() {

	long n, s, m = 0;
	long f, t;

	cin >> n >> s;

	m = s;

	for (long i = 0; i < n; ++i) {
		cin >> f >> t;
		m = max(m, f + t);
	}

	cout << m;

	return 0;
}


#include <iostream>

using namespace std;

int main() {

	long n, s, m = 0;
	long f[100], t[100];

	cin >> n >> s;

	for (long i = 0; i < n; ++i) {
		cin >> f[i] >> t[i];
		m = max(m, f[i] + t[i]);
	}

	cout << m;

	return 0;
}


#include<cstdio>
int main() {
  int n, s, f[100], t[100];
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", f + i, t + i);
  }
  int tmp;
  for (int i = 0; i < n - 1; ++i)
    for (int j = i + 1; j < n; ++j) {
    if (f[j] > f[i]) {
      tmp = t[j];
      t[j] = t[i];
      t[i] = tmp;
      tmp = f[j];
      f[j] = f[i];
      f[i] = tmp;
    }
  }
  int time = 0;
  time = (s - f[0]) < t[0] ? t[0] : (s - f[0]);
  for (int i = 1; i < n; ++i) {
    if (f[i] == f[i - 1])
      continue;
    time += (f[i - 1] - f[i]);
    if (time < t[i])
      time = t[i];
  }
  time += f[n-1];
  printf("%d", time);
  return 0;
}


#include<cstdio>
int main() {
  int n, s, f[100], t[100];
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", f + i, t + i);
  }
  int tmp;
  for (int i = 0; i < n - 1; ++i)
    for (int j = i + 1; j < n; ++j) {
    if (f[j] > f[i]) {
      tmp = t[j];
      t[j] = t[i];
      t[i] = tmp;
      tmp = f[j];
      f[j] = f[i];
      f[i] = tmp;
    }
  }
  int time = 0;
  time = (s - f[0]) < t[0] ? t[0] : (s - f[0]);
  for (int i = 1; i < n; ++i) {
    if (f[i] == f[i - 1])
      continue;
    time += (f[i] - f[i - 1]);
    if (time < t[i])
      time = t[i];
  }
  time += f[n-1];
  printf("%d", time);
  return 0;
}


#include<cstdio>
int main() {
  int n, s, f[100], t[100];
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", f + i, t + i);
  }
  int tmp;
  for (int i = 0; i < n - 1; ++i)
    for (int j = i + 1; j < n; ++j) {
    if (f[j] > f[i]) {
      tmp = t[j];
      t[j] = t[i];
      t[i] = tmp;
      tmp = f[j];
      f[j] = f[i];
      f[i] = tmp;
    }
  }
  int time = 0;
  time += t[0];
  for (int i = 1; i < n; ++i) {
    if (a[i] == a[i - 1])
      continue;
    time += (a[i] - a[i - 1]);
    if (time < t[i])
      time = t[i];
  }
  time += f[n-1];
  printf("%d", time);
  return 0;
}


#include<cstdio>
int main() {
  int n, s, f[100], t[100];
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", f + i, t + i);
  }
  int tmp;
  for (int i = 0; i < n - 1; ++i)
    for (int j = i + 1; j < n; ++j) {
    if (f[j] > f[i]) {
      tmp = t[j];
      t[j] = t[i];
      t[i] = tmp;
      tmp = f[j];
      f[j] = f[i];
      f[i] = tmp;
    }
  }
  int time = 0;
  time += t[0];
  for (int i = 1; i < n; ++i) {
    if (f[i] == f[i - 1])
      continue;
    time += (f[i] - f[i - 1]);
    if (time < t[i])
      time = t[i];
  }
  time += f[n-1];
  printf("%d", time);
  return 0;
}


#include<cstdio>
int main() {
  int n, s, f[100], t[100];
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", f + i, t + i);
  }
  int tmp;
  for (int i = 0; i < n - 1; ++i)
    for (int j = i + 1; j < n; ++j) {
    if (f[j] > f[i]) {
      tmp = t[j];
      t[j] = t[i];
      t[i] = tmp;
      tmp = f[j];
      f[j] = f[i];
      f[i] = tmp;
    }
  }
  int time = 0;
  time = (s - f[0]) < t[0] ? t[0] : (s - f[0]);
  for (int i = 1; i < n; ++i) {
    if (f[i] == f[i - 1]) {
      if (time < t[i])
        time = t[i];
      continue;
    }
    time += (f[i - 1] - f[i]);
    if (time < t[i])
      time = t[i];
  }
  time += f[n-1];
  printf("%d", time);
  return 0;
}


#include <iostream>
#include<string.h>
#include<stdlib.h>
#include<iomanip>
#include<algorithm>
#include<cmath>
using namespace std;
struct data{
	int f, t;
	bool operator<(const data &x)const{
		return f < x.f;
	}
};
data a[100];
int n, s,k;
int main(){
	cin >> n >> s;
	for (int i = 0; i < n; i++){
		cin >> a[i].f >> a[i].t;
	}
	sort(a, a + n);
	k += s - a[n - 1].f;
	if (k < a[n-1].t){
		k = a[n-1].t ;
	}
	for (int i = n - 2; i >= 0; i--){
		k += (a[i + 1].f - a[i].f);
		if (k < a[i].t){
			k = a[i].t;
		}
	}
	k += a[0].f;
	cout << k;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n, s, ans = 0;
    cin >> n >> s;
    vector <pair < int, int > > a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++){
        ans += s - a[i].first;
        s = a[i].first;
        if (ans <= a[i].second)
            ans = a[i].second;
    }
    ans += s;
    cout << ans;
    return 0;
}


#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	int n, s;
	int f[101], t[101], m[101];
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++)
	{
		cin >> f[i];
		cin >> t[i];
		m[i] = t[i] + f[i];
	}

	int m_max = 0;
	for (int i = 1; i < n; i++)
		if (m[i] > m[m_max])
			m_max = i;
	cout << m[m_max];
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	int n, s;
	int f[101], t[101], m[101];
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++)
	{
		cin >> f[i];
		cin >> t[i];
		m[i] = t[i] + f[i];
	}

	int m_max = 0;
	for (int i = 1; i < n; i++)
		if (m[i]  > m[m_max])
			m_max = i;
	cout << max(m[m_max], s);
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>
#include<math.h>
#include<iomanip>
#include<set>

using namespace std;

int main(){

	int n,s;
	int m=0;
	cin>>n>>s;
	int t[1008]={};
	for(int i=0;i<n;i++){
		int a,b;
		cin>>a>>b;
		t[a]=b;
		if(a>m)m=a;
	}

	int ans=0;
	ans+=abs(m-s);
	ans+=t[m];
	for(int i=m-1;i>=0;i--){
		ans++;
		if(ans<t[i])ans+=t[i]-ans;
	}
	cout<<ans;
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>
#include<math.h>
#include<iomanip>
#include<set>

using namespace std;

int main(){

    int n,s;
    int m=0;
    cin>>n>>s;
    int t[1008]={};
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        t[a]=b;
        if(a>m)m=a;
    }

    int ans=0;
    ans+=abs(m-s);
    if(ans<t[m])ans+=t[m]-ans;
    for(int i=m-1;i>=0;i--){
        ans++;
        if(ans<t[i])ans+=t[i]-ans;
    }
    cout<<ans;
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>
#include<math.h>
#include<iomanip>
#include<set>

using namespace std;

int main(){

    int n,s;
    int m=0;
    cin>>n>>s;
    int t[1008]={};
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(t[a]<b)t[a]=b;
        if(a>m)m=a;
    }

    int ans=0;
    ans+=abs(m-s);
    if(ans<t[m])ans+=t[m]-ans;
    for(int i=m-1;i>=0;i--){
        ans++;
        if(ans<t[i])ans+=t[i]-ans;
    }
    cout<<ans;
    return 0;
}


#include <iostream>

using namespace std;
int arr[1000] = { 0 };
int main(){
    int n, s;
    cin >> n >> s;
    for (int i = 0; i < n; i++){
        int f,t;
        cin >> f >> t;
        if (arr[f]<t)
        arr[f] = t;
    }
    int ans = 0;
    for (int i = s; i >0; i--, ans++){
        if (arr[i] > ans) ans += arr[i] - ans;
    }
cout << ans <<endl;

    return 0;
}


#include <iostream>

using namespace std;
int arr[ 1001] = { 0 };
int main(){
    int n, s;
    cin >> n >> s;
    for (int i = 0; i < n; i++){
        int f,t;
        cin >> f >> t;
        if (arr[f]<t)
        arr[f] = t;
    }
    int ans = 0;
    for (int i = s; i >0; i--, ans++){
        if (arr[i] > ans) ans += arr[i] - ans;
    }
cout << ans <<endl;

    return 0;
}


#include <iostream>

using namespace std;
int arr[1001] = { 0 };
int main(){
    int n, s;
    cin >> n >> s;
    for (int i = 0; i < n; i++){
        int f,t;
        cin >> f >> t;
        if (arr[f]<t)
        arr[f] = t;
    }
    int ans = 0;
    for (int i = s; i >0; i--, ans++){
        if (arr[i] > ans) ans += arr[i] - ans;
    }
cout << ans <<endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n, s;
    int *t;
    cin >> n >> s;
    s = s + 1;

    t = new int[s];
    for (int i = 0; i < s; i++)
        t[i] = 0;

    int maxFloor = 0;
    for (int i = 0; i < n; i++)
    {
        int fl;
        cin >> fl;
        cin >> t[fl];
        if (fl > maxFloor)
            maxFloor = fl;
    }

    t[maxFloor] = max(t[maxFloor], maxFloor);
    for (int i = maxFloor - 1; i >= 0; i--)
    {
        t[i] = max(t[i], t[i+1]+1);
    }
    cout << t[0];
    return t[0];
}


#include <iostream>
#include <algorithm>

using namespace std;

void main()
{
    int n, s;
    int *t;
    int maxFloor = 0;

    cin >> n >> s;
    s = s + 1;

    t = new int[s];
    for (int i = 0; i < s; i++)
        t[i] = 0;

    for (int i = 0; i < n; i++)
    {
        int fl;
        cin >> fl;
        cin >> t[fl];
        if (fl > maxFloor)
            maxFloor = fl;
    }

    t[maxFloor] = max(t[maxFloor], maxFloor);
    for (int i = maxFloor - 1; i >= 0; i--)
    {
        t[i] = max(t[i], t[i+1]+1);
    }
    cout << t[0];
}


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

typedef long long int u;

int main() {
    u t;
    cin>>t;
    while(t--)
    {
        u n;
        u sum=0;
        for(u i=1;i<n/2;i++)
        {
            sum=sum+8*i*i;
        }
        cout<<sum<<endl;
    }
    return 0;
}


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

typedef long long int u;

int main() {
    u t;
    cin>>t;
    while(t--)
    {
        u n;cin>>n;
        u sum=0;
        for(u i=1;i<=n/2;i++)
        {
            sum=sum+8*i*i;
        }
        cout<<sum<<endl;
    }
    return 0;
}


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

typedef long long int u;

int main() {
    u t;
    cin>>t;
    while(t--)
    {
        u n;
        u sum=0;
        for(u i=1;i<(n-1)/2;i++)
        {
            sum=sum+8*i*i;
        }
        cout<<sum<<endl;
    }
    return 0;
}


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

typedef long long int u;

int main() {
    u t;
    cin>>t;
    while(t--)
    {
        u n;
        u sum=0;
        for(u i=1;i<=n/2;i++)
        {
            sum=sum+8*i*i;
        }
        cout<<sum<<endl;
    }
    return 0;
}


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

long long int solve(int n)
{
    if(n==1)
    {
        return 0;
    }
    if(n==3)
    {
        return 8;
    }
    return n*solve(n-2);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<solve(n)<<endl;
    }
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<0<<endl;
        }
        int ans=1,i,k;
        for(i=0;i<n/2;i++)
        {
            ans=ans*k;
            k*=8;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits\stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<"0"<<endl;
        }
        else
        {
            int i=1,m=8,k=1,ans=0;
            while(k<n)
            {
                ans=ans+i*m;
                m=m+8;
                i++;
                k=k+2;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
            int i,k=8;
            unsigned long long int ans=0;
            for(i=1;i<=n/2;i++)
            {
                ans=ans+i*k;
                k+=8;
            }
            cout<<ans<<endl;
    }
    return 0;
}


#include<bits\stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<"0"<<endl;
        }
        else
        {
            int i=1,m=8,k=1;
            while(k<n)
            {
                ans=ans+i*m;
                m=m+8;
                i++;
                k=k+2;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
            int ans=0,i,k=8;
            for(i=1;i<=n/2;i++)
            {
                ans=ans+i*k;
                k+=8;
            }
            cout<<ans<<endl;
    }
    return 0;
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
            int i,k=8;
         int ans=0;
            for(i=1;i<=n/2;i++)
            {
                ans=ans+i*k;
                k+=8;
            }
            cout<<ans<<endl;
    }
    return 0;
}


#include<bits\stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<"0"<<endl;
        }
        else
        {
            long long int i=1,m=8,k=1,ans=0;
            while(k<n)
            {
                ans=ans+i*m;
                m=m+8;
                i++;
                k=k+2;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


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

unsigned long long int solve(int n)
{
    int a[n+1];
    a[1]=0;
    a[3]=8;
    for(i=5;i<n+1;i=i+2)
    {
        a[i]=i*a[n-2];
    }
    return a[n];
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<0<<endl;
        }
        int ans=1,i,k;
        for(i=0;i<n/2;i++)
        {
            ans=ans*k;
            k*=8;
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

unsigned long long int solve(int n)
{
    if(n==1)
    {
        return 0;
    }
    if(n==3)
    {
        return 8;
    }
    return n*solve(n-2);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<solve(n)<<endl;
    }
}


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

long long int solve(int n)
{
    if(n==1)
    {
        return 0;
    }
    if(n==3)
    {
        return 8;
    }
    return n*solve(n-2);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<solve(n)<<endl;
    }
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
            int ans=0,i,k;
            for(i=0;i<=n/2;i++)
            {
                ans=ans+i*k;
                k*=8;
            }
            cout<<ans<<endl;
    }
    return 0;
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<0<<endl;
        }
        else
        {
            int ans=1,i,k;
            for(i=0;i<n/2;i++)
            {
                ans=ans*k;
                k*=8;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


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

unsigned long long int solve(int n)
{
    int a[n+1];
    a[1]=0;
    a[3]=8;
    for(i=5;i<n+1;i=i+2)
    {
        a[i]=i*a[n-2];
    }
    return a[n];
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<solve(n)<<endl;
    }
    return 0;
}


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

unsigned long long int solve(int n)
{
    if(n==1)
    {
        return 0;
    }
    if(n==3)
    {
        return 8;
    }
    return n*solve(n-2);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<solve(n)<<endl;
    }
    return 0;
}


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

unsigned long long int solve(int n)
{
    int a[n+1],i;
    a[1]=0;
    a[3]=8;
    for(i=5;i<n+1;i=i+2)
    {
        a[i]=i*a[n-2];
    }
    return a[n];
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<solve(n)<<endl;
    }
    return 0;
}


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

unsigned long long int solve(int n)
{
    if(n<=0)
    {
        return;
    }
    if(n==1)
    {
        return 0;
    }
    if(n==3)
    {
        return 8;
    }
    n=n*solve(n-2);
    return n;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        unsigned long long int n;
        cin>>n;
        cout<<solve(n)<<endl;
    }
}


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

unsigned long long int solve(int n)
{
    int a[n+1];
    a[1]=0;
    a[3]=8;
    for(i=5;i<n+1;i=i+2)
    {
        a[i]=i*a[n-2];
    }
    return a[n];
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<0<<endl;
        }
        int ans=1,i;
        for(i=0;i<n/2;i++)
        {
            ans=ans*k;
            k*=8;
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

unsigned long long int solve(int n)
{
    if(n<=0)
    {
        return n;
    }
    if(n==1)
    {
        return 0;
    }
    if(n==3)
    {
        return 8;
    }
    n=n*solve(n-2);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<solve(n)<<endl;
    }
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
            int i,k=8;
            unsigned int ans=0;
            for(i=1;i<=n/2;i++)
            {
                ans=ans+i*k;
                k+=8;
            }
            cout<<ans<<endl;
    }
    return 0;
}


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

unsigned long long int solve(int n)
{
    if(n<=0)
    {
        return;
    }
    if(n==1)
    {
        return 0;
    }
    if(n==3)
    {
        return 8;
    }
    return n*solve(n-2);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<solve(n)<<endl;
    }
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
            int ans=0,i,k=8;
            for(i=0;i<=n/2;i++)
            {
                ans=ans+i*k;
                k+=8;
            }
            cout<<ans<<endl;
    }
    return 0;
}


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

int main()
{
	int t;
	cin>>t;
	long long int res[t];
	for(int i=0;i<t;i++)
	{
		long long int n;
		cin>>n;
		if(n==1)
		res[i]=0;
		else
		{
			long long sum=0;
			for(long long int j=1;j<=(n-1)/2;j++)
			sum=sum+(8*j*j);
			res[i]=sum;
		}
	}
	for(int i=0;i<t;i++)
	cout<<res[i]<<endl;
	return 0;
}


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

typedef long long ll;

int main()
{
	int t;
	cin>>t;
	ll int res[t];
	for(int i=;i<t;i++)
	{
		ll int n;
		cin>>n;
		if(n==1)
		res[i]=0;
		else
		{
			for(int j=0;j<=((n-1)/2);j++)
			res[i]=res[i]+(8*j*j);
		}
	}
	for(int i=0;i<t;i++)
	cout<<res[i]<<endl;
	return 0;
}


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

typedef long long ll;

int main()
{
	int t;
	cin>>t;
	ll res[t];
	for(int i=0;i<t;i++)
	{
		ll n;
		cin>>n;
		if(n==1)
		res[i]=0;
		else
		{
			for(int j=1;j<=((n-1)/2);j++)
			res[i]=res[i]+(8*j*j);
		}
	}
	for(int i=0;i<t;i++)
	cout<<res[i]<<endl;
	return 0;
}


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

int main()
{
	int t;
	cin>>t;
	long long int res[t];
	for(int i=0;i<t;i++)
	{
		long long int n;
		cin>>n;
		if(n==1)
		res[i]=0;
		else
		{
			long long sum=0;
			for(int j=1;j<=((n-1)/2);j++)
			sum=sum+(8*j*j);
			res[i]=sum;
		}
	}
	for(int i=0;i<t;i++)
	cout<<res[i]<<endl;
	return 0;
}


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

typedef long long ll;

int main()
{
	int t;
	cin>>t;
	ll int res[t];
	for(int i=0;i<t;i++)
	{
		ll int n;
		cin>>n;
		if(n==1)
		res[i]=0;
		else
		{
			for(int j=1;j<=((n-1)/2);j++)
			res[i]=res[i]+(8*j*j);
		}
	}
	for(int i=0;i<t;i++)
	cout<<res[i]<<endl;
	return 0;
}


#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    int ninputs;
    cin>>ninputs;
    for(int i=0;i<ninputs;i++){
        int number;
        cin>>number;
        int quot = number/2;
       // cout<<quot;
        if(quot!=0){
        int fnum = 8 * quot ;
        int sum=0;
        for(int j=quot; j>0;j--){
            int add;
            add = fnum*j;
            sum+=add;
            fnum-=8;

        }
        cout<<sum;
        cout<<"\n";
        }
        else{
            cout<<0;
            cout<<"\n";
        }

    }

    // cout<<k;
    return 0;
}


#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    int ninputs;
    cin>>ninputs;
    for(int i=0;i<ninputs;i++){
        double number;
        cin>>number;
       long int quot = number/2;
       // cout<<quot;
        if(quot!=0){
        long int fnum = 8 * quot ;
        long int sum=0;
        for( long int j=quot; j>0;j--){
            long int add;
            add = fnum*j;
            sum+=add;
            fnum-=8;

        }
        cout<<sum;
        cout<<"\n";
        }
        else{
            cout<<0;
            cout<<"\n";
        }

    }

    // cout<<k;
    return 0;
}


#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    int ninputs;
    cin>>ninputs;
    for(int i=0;i<ninputs;i++){
        double number;
        cin>>number;
       long int quot = number/2;
       // cout<<quot;
        if(quot!=0){
        long long fnum = 8 * quot ;
        long long sum=0;
        for( long long j=quot; j>0;j--){
            long long add;
            add = fnum*j;
            sum+=add;
            fnum-=8;

        }
        cout<<sum;
        cout<<"\n";
        }
        else{
            cout<<0;
            cout<<"\n";
        }

    }

    // cout<<k;
    return 0;
}


#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    int ninputs;
    cin>>ninputs;
    for(int i=0;i<ninputs;i++){
        int number;
        cin>>number;
        int quot = number/2;
        if(quot!=0){
        int fnum = 8 * quot ;
        int sum=0;
        for(int j=quot; j>1;j--){
            int add;
            add = fnum*j;
            sum+=add;
            fnum-=8;

        }
        cout<<sum;
        cout<<"\n";
        }
        else{
            cout<<0;
            cout<<"\n";
        }

    }

    // cout<<k;
    return 0;
}


#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    int ninputs;
    cin>>ninputs;
    for(int i=0;i<ninputs;i++){
        double number;
        cin>>number;
       long int quot = number/2;
       // cout<<quot;
        if(quot!=0){
        long int fnum = 8 * quot ;
        long int sum=0;
        for( long int j=quot; j>0;j--){
            long long add;
            add = fnum*j;
            sum+=add;
            fnum-=8;

        }
        cout<<sum;
        cout<<"\n";
        }
        else{
            cout<<0;
            cout<<"\n";
        }

    }

    // cout<<k;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int t;
long long n;

int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    cout << (n - 1) * n * (n + 1) / 3 << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int t;
long long n;

// sum(i^2 | i=1..n) = n(n+1)(2n+1)/6
// sum(8i^2 | i=1..n/2) = n*(n^2-1)/3

int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    cout << n * (n * n - 1) / 3 << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int t;
long long n;

// sum(i^2 | i=1..n) = n(n+1)(2n+1)/6
// sum(8i^2 | i=1..n/2) = n*(n^2-1)/3 (represent n as 2k+1)

int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    cout << n * (n * n - 1) / 3 << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int t, n;

int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    long long result = 0;
    for (int i = 1; i <= n / 2; i++) {
      result += 8ll * i * i;
    }
    cout << result << endl;
  }
  return 0;
}


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

int main()
{
    int t; cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long ans=0;
        for(int i=1; i<n/2; i++)
        {
            ans += i*i;
        }
        cout<<ans*8<<endl;
    }
    return 0;
}


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

int main()
{
    int t; cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long ans=0;
        for(int i=1; i<n/2; i++)
        {
            ans += i * 1ll * i;
        }
        cout<<ans*8<<endl;
    }
    return 0;
}


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

int main()
{
    int t; cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long ans=0;
        for(int i=1; i<=n/2; i++)
        {
            ans += i * 1ll * i;
        }
        cout<<ans*8<<endl;
    }
    return 0;
}


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

int main()
{
    int t; cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long ans=0;
        for(int i=1; i<n/2; i++)
        {
            ans += i*i;
        }
        cout<<ans*8<<endl;
    }
    return 0;
}


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

int main()
{
    int t; cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long ans=0;
        for(int i=1; i<=n/2; ++i)
        {
            ans += i * 1ll * i;
        }
        cout<<ans*8<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,sum=0;
        cin>>n;
        while((n/2)>=1)
        {
            sum=sum+pow((8*(n/2)),(n/2));
            (n/2)--;
        }
        cout<<sum<<endl;

    }


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long int n,sum=0,a;
        cin>>n;
        a=n/2;
        while(a>=1)
        {
            sum=sum+((8*a)*a);
            a--;
        }
        cout<<sum<<endl;

    }
    return 0;
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long int n,sum=0,a;
        cin>>n;
        a=n/2;
        while(a>=1)
        {
            sum=sum+((8*a)*a);
            a--;
        }
        cout<<sum<<endl;

    }
    return 0;
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,sum=0,a;
        cin>>n;
        a=n/2;
        while(a>=1)
        {
            sum=sum+((8*a)*a);
            a--;
        }
        cout<<sum<<endl;

    }
    return 0;
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,sum=0,a;
        cin>>n;
        a=n/2;
        while(a>=1)
        {
            sum=sum+pow((8*a),a);
            a--;
        }
        cout<<sum<<endl;

    }


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,sum=0,a;
        cin>>n;
        a=n/2;
        while(a>=1)
        {
            sum=sum+pow((8*a),a);
            a--;
        }
        cout<<sum<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long int fum (long long int a);
long long int sum;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >>t;
    for (int i=0;i<t;i++)
    {
     long long k;

    cin >> k;
    cout << fum (k)<<endl;
}

}
long long int fum (long long int a)
{

	if (a==1)
	{
		return sum;
	}
	else
	{
		sum=sum+((a-1)*4)*((a-1)/2);
		a=a-2;
		return(fum(a));
	}

}


#include <bits/stdc++.h>
using namespace std;
long long int fum (long long int a);
long long int sum;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >>t;
    for (int i=0;i<t;i++)
    {
     long long k;

    cin >> k;
    cout << fum (k);
}

}
long long int fum (long long int a)
{

	if (a==1)
	{
		return sum;
	}
	else
	{
		sum=sum+((a-1)*4)*((a-1)/2);
		a=a-2;
		return(fum(a));
	}

}


#include <bits/stdc++.h>
using namespace std;
long long int fum (long long int a);
long long int sum,u;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,p;

    cin >>t;
    for (int i=0;i<t;i++)
    {
     long long k;

    cin >> k;
    cout << fum (k)<<endl;
}

}
long long int fum (long long int a)
{

	u=sum;
	if (a==1)
	{
		sum=0;
		return u;

	}
	else
	{
		sum=sum+((a-1)*4)*((a-1)/2);
		a=a-2;
		return(fum(a));
	}

}


#include <bits/stdc++.h>
using namespace std;
long long int fum (long long int a);
long long int sum;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
     long long k;
    cin >> k;
    cout << fum (k);

}
long long int fum (long long int a)
{

	if (a==1)
	{
		return sum;
	}
	else
	{
		sum=sum+((a-1)*4)*((a-1)/2);
		a=a-2;
		return(fum(a));
	}

}


#include <bits/stdc++.h>
using namespace std;
long long int fum (long long int a);
long long int sum;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,p;
    cin >>t;
    for (int i=0;i<t;i++)
    {
     long long k;

    cin >> k;
    cout << fum (k)<<endl;
}

}
long long int fum (long long int a)
{

	if (a==1)
	{
		return sum;

	}
	else
	{
		sum=sum+((a-1)*4)*((a-1)/2);
		a=a-2;
		return(fum(a));
	}

}


#include <bits/stdc++.h>
using namespace std;
long long int fum (long long int a);
long long int sum;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,p;

    cin >>t;
    for (int i=0;i<t;i++)
    {
     long long k;

    cin >> k;
    cout << fum (k)<<endl;
}

}
long long int fum (long long int a)
{
	int u;
	u=sum;
	if (a==1)
	{
		sum=0;
		return u;

	}
	else
	{
		sum=sum+((a-1)*4)*((a-1)/2);
		a=a-2;
		return(fum(a));
	}

}


#include <iostream>
using namespace std;

int main(){

    int n,t;
    cin>>t;
    int steps=1;
    int surround=3;
    for(int i=0;i<t;i++){
    long long minimum=0;
        cin>>n;
        while(surround<=n){
            minimum+=((surround*4ll)-4)*steps;
            surround+=2;
            steps++;
        }
        cout<<minimum<<endl;
        surround=3;
        steps=1;
}
    return 0;
}


#include <iostream>
using namespace std;

int main(){

    int n,t;
    cin>>t;
    int steps=1;
    int surround=3;
    for(int i=0;i<t;i++){
    long long minimum=0;
        cin>>n;
        while(surround<=n){
            minimum+=((surround*4*1ll)-4*1ll)*steps;
            surround+=2;
            steps++;
        }
        cout<<minimum<<endl;
}
    return 0;
}


#include <iostream>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n
        long lnog minimum=0;
        cin>>n;
        for(int i=0;i<n/2;i++){
            minimum+=i*1ll*i;
        }
        cout<<minimum*8<<endl;
    }

    return 0;
}


#include <iostream>
using namespace std;

int main(){

    int n,t;
    cin>>t;
    int steps=1;
    int surround=3;
    for(int i=0;i<t;i++){
    long long minimum=0;
        cin>>n;
        while(surround<=n){
            minimum+=((surround*4*1ll)-4)*steps;
            surround+=2;
            steps++;
        }
        cout<<minimum<<endl;
}
    return 0;
}


#include <iostream>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        long long minimum=0;
        cin>>n;
        for(int i=0;i<n/2;i++){
            minimum+=i*1ll*i;
        }
        cout<<minimum*8<<endl;
    }

    return 0;
}


#include <iostream>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        long long minimum=0;
        cin>>n;
        for(int i=1;i<n/2;i++){
            minimum+=i*1ll*i;
        }
        cout<<minimum*8<<endl;
    }

    return 0;
}


#include <iostream>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        long long minimum=0;
        cin>>n;
        for(int i=0;i<=n/2;i++){
            minimum+=i*1ll*i;
        }
        cout<<minimum*8<<endl;
    }

    return 0;
}


#include <iostream>
using namespace std;

int main(){

    int n,t;
    cin>>t;
    int steps=1;
    int surround=3;
    for(int i=0;i<t;i++){
    long long minimum=0*1ll;
        cin>>n;
        while(surround<=n){
            minimum+=((surround*4)-4)*steps;
            surround+=2;
            steps++;
        }
        cout<<minimum<<endl;
}
    return 0;
}