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

const int N=100100;
int a[N],b[N],n,m,vis[N],fa[N],c[N];
typedef long long ll;
vector<int>g[N];
ll sum[N],mn[N];
bool cmp(const int&x,const int&y){
	if(a[x]!=a[y])return a[x]<a[y];
	return b[x]>b[y];
}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;++i){cin>>a[i]>>b[i];c[i]=i;}
	sort(c+1,c+n+1,cmp);
	for(int i=1;i<=m;++i){
		int x,y;cin>>x>>y;
		g[x].push_back(y);g[y].push_back(x);
	}
	for(int i=1;i<=n;++i)fa[i]=i;//,sort(g[i].begin(),g[i].end(),cmp);
	for(int i=1;i<=n;++i){
		int u=c[i];sum[u]=b[u];mn[u]=max(0,a[u]-b[u]);
		vis[u]=1;
		for(int j:g[u])if(vis[j]){
			int v=find(j);if(u==v)continue;
			sum[u]+=sum[v];mn[u]=min(mn[u],max(a[u]-sum[v]-b[u],mn[v]));
			fa[v]=u;
		}
	}
	cout<<sum[c[n]]+mn[c[n]]<<'\n';
	return 0;
}
