#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<vector>
#define ll long long
using namespace std;

const int N=100005;

int n,m,x,y,cnt;
int a[N],b[N],fa[N],id[N],son[N],vis[N];
ll dp[N],sum[N];
vector<int> lev[N];

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

int find(int k){
	if (fa[k]!=k) fa[k]=find(fa[k]);
	return fa[k];
}

int main(){
	int i,j;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
		a[i]=max(a[i]-b[i],0);
		id[i]=i;
	}
	for (i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		lev[x].push_back(y);
		lev[y].push_back(x);
	}
	sort(id+1,id+1+n,cmp);
	for (i=1;i<=n;i++) fa[i]=i;
	for (i=1;i<=n;i++){
		cnt=0; x=id[i]; vis[x]=1; sum[x]=1ll*b[x];
		for (j=0;j<lev[x].size();j++){
			y=lev[x][j];
			if (!vis[y]||find(x)==find(y)) continue;
			son[++cnt]=find(y);
			sum[x]+=1ll*sum[find(y)];
			fa[find(y)]=find(x);
		}
		dp[x]=sum[x]+1ll*a[x];
		for (j=1;j<=cnt;j++) dp[x]=min(dp[x],sum[x]-sum[son[j]]+max(1ll*a[x],dp[son[j]]));
	}
	printf("%lld\n",dp[id[n]]);
	return 0;
}