#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node{
    int x,v;
    node(int a=0,int b=0){x=a;v=b;}
}p[100010];
int h[100010],nex[200010],to[200010],a[100010],b[100010],fa[100010],M;
ll s[100010],f[100010];
bool v[100010];
void add(int a,int b){
    M++;
    to[M]=b;
    nex[M]=h[a];
    h[a]=M;
}
bool operator<(node a,node b){return a.v<b.v;}
int get(int x){return x==fa[x]?x:(fa[x]=get(fa[x]));}
int main(){
    int n,m,i,j,x,y;
    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);
        p[i]=node(i,a[i]);
    }
    while(m--){
        scanf("%d%d",&x,&y);
        add(x,y);
        add(y,x);
    }
    sort(p+1,p+n+1);
    for(i=1;i<=n;i++){
        fa[i]=i;
        s[i]=b[i];
        f[i]=a[i];
    }
    for(i=1;i<=n;i++){
        v[p[i].x]=1;
        for(j=h[p[i].x];j;j=nex[j]){
            if(v[to[j]]){
                x=get(p[i].x);
                y=get(to[j]);
                if(x==y)continue;
                fa[y]=x;
                s[x]+=s[y];
                f[x]=min(f[x],max(f[y],a[x]-s[y]));
            }
        }
    }
    x=get(1);
    printf("%lld",f[x]+s[x]);
}