#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=100100;
vector<int> arrive[MAXN];
int a[MAXN],b[MAXN],p[MAXN];
int fa[MAXN];
int f[MAXN],s[MAXN],vis[MAXN];
int n,m;
inline int find(register int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
inline void Addedge(register int u,register int v)
{
	arrive[u].push_back(v);
	return;
}
inline bool cmp_(register int x,register int y)
{
	return a[x]<a[y];
}
signed main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(register int i=1;i<=n;i++) cin>>a[i]>>b[i],a[i]=max(a[i]-b[i],0LL),p[i]=fa[i]=i;
	sort(p+1,p+n+1,cmp_);
	for(register int i=1,x,y;i<=m;i++) cin>>x>>y,Addedge(x,y),Addedge(y,x);
	for(register int i=1;i<=n;i++)
	{
		vector<int> sonnow;
		register int now=p[i];
		vis[now]=1,s[now]=b[now];
		for(register int i=0;i<(int)arrive[now].size();i++)
		{
			register int val=arrive[now][i];
			if((!vis[val])||find(now)==find(val)) continue;
			sonnow.push_back(find(val));
			s[now]+=s[find(val)];
			fa[find(val)]=now;
		}
		f[now]=s[now]+a[now];
		for(register int i=0;i<(int)sonnow.size();i++) f[now]=min(f[now],s[now]-s[sonnow[i]]+max(a[now],f[sonnow[i]]));
	}
	cout<<f[p[n]]<<endl;
	return 0;
}