#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N = 100005, inf = 2e9;

ll n, m, a[N], b[N], inv[N], s;

vector<ll> adj[N];
pll o[N];

ll p[N], v[N];
bool c[N];

ll Find (ll X) {
	if(p[X] == X) return X;
	return p[X] = Find(p[X]);
}

bool can (ll X) {
	for(ll i=1;i<=n;i++) {
		p[i] = i;
		v[i] = b[i];
	}
	for(ll i=1;i<=n;i++) {
		ll I = o[i].Y;
		c[I] = (a[I]-b[I] <= X);
		for(auto &T : adj[I]) {
			if(inv[T] >= i) continue;
			T = Find(T);
			if(T == I) continue;
			if(c[T] && a[I]-b[I] <= v[T]+X) c[I] = true;
			v[I] += v[T];
			p[T] = I;
		}
	}
	return c[Find(1)];
}

int main()
{
	scanf("%lld%lld",&n,&m);
	for(ll i=1;i<=n;i++) {
		scanf("%lld%lld",&a[i],&b[i]);
		o[i] = {a[i]-b[i], i};
		s += b[i];
	}
	sort(o+1, o+1+n);
	for(ll i=1;i<=n;i++) {
		inv[o[i].Y] = i;
	}
	for(ll i=1;i<=m;i++) {
		ll A, B;
		scanf("%lld%lld",&A,&B);
		adj[A].push_back(B);
		adj[B].push_back(A);
	}
	ll S = 0, E = inf;
	while(S<E) {
		ll M = (S+E)/2;
		can(M) ? E = M : S = M+1;
	}
	printf("%lld\n",S+s);
}
