#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60) + 1e9;
const Int mod = (1e9)+7;
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class UF{
public:
  Int V;
  vector<Int> par,rnk,sz;
  UF(){}
  UF(Int V):V(V),par(V),rnk(V,0),sz(V,1){for(Int i=0;i<V;i++)par[i]=i;}
  
  Int find(Int x){
    assert(x < V);
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(Int x,Int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rnk[x]<rnk[y])par[x]=y, sz[y] += sz[x];
    else{
      par[y]=x;
      sz[x] += sz[y];
      if(rnk[x]==rnk[y])rnk[x]++;
    }
  }

  bool same(Int x,Int y){return find(x)==find(y);}

  Int size(Int x){return sz[find(x)];}
};


Int n;
vector<vector<Int> > G;
vector<Int> A, B;

Int solve(){
  vector<Int> ord(n); iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](Int a,Int b){return A[a] - B[a] < A[b] - B[b];});
  vector<Int> dp(n,INF);
  
  UF uf(n);
  for(Int i=0;i<n;i++) uf.sz[i] = B[i];
  
  vector<Int> used(n, 0);
  for(Int v:ord){
    assert(v == uf.find(v));
    Int c = max(0LL, A[v] - B[v]);
    used[v] = 1;
    Int mn = INF;
    for(Int to:G[v]){
      to = uf.find(to);
      if(used[to] == 0) continue;
      Int a = max(0LL, c - uf.size(to));
      Int b = dp[to];
      Min(mn, max(a, b));
    }
    
    for(Int to:G[v]){
      to = uf.find(to);
      if(used[to]) uf.unite(v, to);
    }
    
    v = uf.find(v);
    if(mn == INF) mn = c;
    dp[v] = mn;
  }

  Int res = accumulate(B.begin(), B.end(), 0LL);
  assert(res == uf.size(0));
  Int last = uf.find(ord.back());
  res += max(0LL, dp[last]);
  return res;
}

signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int m;
  cin>>n>>m;
  G.resize(n);
  A.resize(n); B.resize(n);
  for(Int i=0;i<n;i++) cin>>A[i]>>B[i];
  
  for(Int i=0;i<m;i++){
    Int u, v;
    cin>>u>>v; u--, v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  
  Int ans = solve();
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 12544