#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef vector<int> vi;
#define pb push_back
typedef long long ll;

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,m,a[N],b[N],fa[N],id[N];
ll s[N],f[N];
vi E[N];
bool vis[N];

int getf(int x) {
	return x==fa[x]?x:fa[x]=getf(fa[x]);
}

bool cmp(int x,int y) {
	return a[x]<a[y];
}

int main() {
	cin>>n>>m;
	for(int i=1;i<=n;i++) {
		a[i]=gi(),b[i]=gi();
		a[i]=max(a[i]-b[i],0);
		id[i]=fa[i]=i;s[i]=b[i];f[i]=a[i];
	}
	for(int i=1,u,v;i<=m;i++) u=gi(),v=gi(),E[u].pb(v),E[v].pb(u);
	sort(id+1,id+n+1,cmp);
	for(int i=1;i<=n;i++) {
		int u=id[i];vis[u]=1;
		for(auto v:E[u])
			if(vis[v]) {
				int x=getf(u),y=getf(v);
				if(x!=y) {
					s[x]+=s[y];fa[y]=x;f[x]=min(f[x],max(f[y],a[x]-s[y]));
				}
			}
	}
	int x=getf(1);cout<<f[x]+s[x];
	return 0;
}
