#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
int n,m,ed,a[N],fir[N],vis[N],b[N],id[N],c[N],f[N];
ll sum[N],g[N];
struct E{int v,nxt;}e[N*2];  
void adde(int x,int y){
	e[++ed].v=y;e[ed].nxt=fir[x];fir[x]=ed;
}
bool cmp(int x,int y){
	return c[x]<c[y]; 
} 
int F(int x){return x==f[x]?x:f[x]=F(f[x]);}
int main(){
	//freopen("aa.in","r",stdin);
	int i,j;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i){
		scanf("%d%d",a+i,b+i);
		c[i]=max(a[i]-b[i],0);	
	}
	for(i=1;i<=m;++i){
		int x,y;scanf("%d%d",&x,&y);
		adde(x,y);adde(y,x);
	}
	for(i=1;i<=n;++i)f[i]=id[i]=i,g[i]=c[i],sum[i]=b[i];
	sort(id+1,id+1+n,cmp);
	for(i=1;i<=n;++i){
		int x=id[i];vis[x]=1;
		for(j=fir[x];j;j=e[j].nxt)if(vis[e[j].v]){
			int y=e[j].v;
			if(x==F(y))continue;
			//printf("%d %d\n",x,y);
			//printf("con %d %d ,f %d %d : %d %d\n",x,y,f[x],f[y],sum[f[x]],sum[f[y]]);
			g[x]=min(g[x],g[f[y]]+max(c[x]-g[f[y]]-sum[f[y]],0LL));
			//printf("g %lld\n",g[f[x]]);		
			sum[x]+=sum[f[y]];
			f[f[y]]=x;
		}
	} 
	//printf("fin sum %lld\n",sum[F(1)]); 
	ll ans=g[F(1)]+sum[F(1)];
	cout<<ans<<endl;
	return 0;
} 