#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=100007;
int a[maxn],n,m,f[maxn],vis[maxn],sum[maxn],b[maxn],c[maxn],p[maxn],fa[maxn];
vector<int>v[maxn];
int find(int x){return fa[x]==x?fa[x]:fa[x]=find(fa[x]);}
inline bool cmp(int x,int y){return c[x]<c[y];}
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;++i)cin>>a[i]>>b[i],p[i]=fa[i]=i,c[i]=max(a[i]-b[i],0ll);
	sort(p+1,p+1+n,cmp);
	for(int i=1,x,y;i<=m;++i){
		cin>>x>>y;v[x].push_back(y);v[y].push_back(x);
	}
	for(int i=1;i<=n;++i){
		int x=p[i];vis[x]=1;
		sum[x]=b[x];vector<int>son;
		for(auto y:v[x])if(find(y)^find(x)&&vis[y])sum[x]+=sum[find(y)],son.push_back(find(y)),fa[find(y)]=find(x);
		f[x]=sum[x]-b[x]+max(a[x],b[x]);
		for(auto y:son)f[x]=min(f[x],sum[x]-b[x]-sum[y]+max(max(a[x],b[x]),f[y]+b[x]));
	}
	cout<<f[p[n]];
}