#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int INF = 1000000007;
int A[MAXN], max_reachable[MAXN];
vector <int> G[MAXN];
int main(int argc, char const *argv[])
{
	int n, m;
	cin>>n>>m;
	for (int i = 1; i <= n; ++i)
	{
		cin>>A[i];
	}
	for (int i = 0; i < m; ++i)
	{
		int u, v;
		cin>>u>>v;
		G[u].push_back(v);
	}

	int ans = -INF;
	for (int i = n; i >= 1; --i)
	{
		max_reachable[i] = -INF;
		for (int j = 0; j < (int)G[i].size(); ++j)
		{
			int v = G[i][j];
			max_reachable[i] = max(max_reachable[i], max_reachable[v]);
		}
		
		ans = max(ans, max_reachable[i] - A[i]);

		max_reachable[i] = max(max_reachable[i], A[i]);
	}

	cout<<ans<<"\n";
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define fst ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endk cout<<"\n";
typedef long long int ll;
typedef long int l;
#define l(i,a,b) for(i=a;i<b;i++)
#define lo(i,a,b) for(i=a;i>=b;i--)
#define s(v) sort(v.begin(),v.end());
#define pb push_back;
#define vll vector<ll>
#define vint vector<int>
#define test() ll t;cin>>t;while(t--){solve();};
#define test1() int t=1;while(t--){solve();};
bool isprime(ll x)
{
    if(x==1) return false;
    if(x==2 || x==3) return true;
    if(x%2==0 || x%3==0) return false;
    for(ll i=5;i*i<=x;i+=6)
    {
        if(x%i==0 || x%(i+2)==0) return false;
    }
    return true;
}
ll power(ll x,ll y)
{
	ll ans=1;
	while(y>0)
	{
		if(y&1) ans=ans*x;
		x=x*x;
		y=y>>1;
	}
	return ans;
}
bool comp(pair<ll,ll> a,pair<ll,ll> b)
{
    return (a.first<b.first);
}
int solve()
{
    ll n,k,ans=0,i,curr=0;
    cin>>n>>k;
    vector<pair<ll,ll>> v(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i].first>>v[i].second;
    }
    sort(v.begin(),v.end(),comp);
    for(i=0;i<n;i++)
    {
        if(v[i].first-curr<=k)
        {
            k-=(v[i].first-curr);
            curr=v[i].first;
            k+=v[i].second;
        }
        else
        {
            curr+=k;
            break;
        }
    }
    if(i==n)
    {
        curr+=k;
    }
    cout<<curr;
    return 0;
}
int main()
{
    fst;
    test1();
    return 0;
}
