#include <bits/stdc++.h> 
using namespace std;

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

int const MAX = 1e5 + 41;

int n, m;
int a[MAX];
int b[MAX];
int c[MAX];
vi e[MAX];

vi e1[MAX];

bool cmp(int i, int j) {
	return c[i] < c[j];
}

int par[MAX];

int find(int x) {
	if (par[x] == x) return x;
	return par[x] = find(par[x]);
}

bool uni(int a, int b) {
	a = find(a);
	b = find(b);
	if (a == b) return false;
	par[b] = a;
	return 1;
}

ll d[MAX];
ll ds[MAX];
ll const INF = 1e18;

void dfs(int x) {
	ds[x] = b[x];
	for (int y : e1[x]) {
		dfs(y);
		ds[x] += ds[y];
	}
	
	vpll v;
	for (int y : e1[x]) {
		v.pb(mp(d[y], y));		
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	ll res = INF;
	if (sz(e1[x]) > 0) {
		ll sum = ds[x];		
		int k = sz(v);
		vll f(k, 0);
		vll suf(k, 0);
		fi(0, sz(v) - 1) {
			int id = v[i].second;
			sum -= ds[id];
			f[i] = v[i].first - sum;			
		}
		fdi(k - 1, 0) {
			suf[i] = f[i];
			if (i + 1 < k) {
				suf[i] = max(suf[i], suf[i + 1]);
			}
		}

		ll pref = 0;
		fi(0, k - 1) {
			int id = (int) v[i].second;

			ll sf = (i + 1 < k ? suf[i + 1] : 0);
			sf = max(0LL, sf - ds[id]);
			ll me = max(0LL, c[x] - ds[id]);
			ll to = v[i].first;
			ll pres = max(pref, max(sf, max(me, to)));
			
			res = min(res, pres);

			pref = max(pref, f[i]);				
		}
	} else {
		res = c[x];
	}

	d[x] = res;
}

ll ans;

void solve() {
	fi(1, n) {
		c[i] = max(0, a[i] - b[i]);
	}

	vi v;
	fi(1, n) {
		v.pb(i);
	}
	sort(v.begin(), v.end(), cmp);

	fi(1, n) {
		sort(e[i].begin(), e[i].end(), cmp);
	}

	fi(1, n) {
		par[i] = i;
	}
	
	for (int x : v) {
		for (int z : e[x]) {
			int y = find(z);
			if (c[y] > c[x]) continue;
			if (find(x) != find(y)) {
				e1[x].pb(find(y));
				uni(x, y);
			}
		}
	}	

	fi(1, n) {
		sort(e1[i].begin(), e1[i].end());
		e1[i].resize(unique(e1[i].begin(), e1[i].end()) - e1[i].begin());
	}

/*	
	err("root = %d\n", find(1));
	fi(1, n) {
		err("x = %d c = %d:\n", i, c[i]);
		for (int y : e1[i]) {
			err("y = %d\n", y);
		}
		err("\n");
	}
*/

	dfs(find(1));

	ans = d[find(1)];	
	fi(1, n) {
		ans += b[i];
	}

/*
	fi(1, n) {
		err("i = %d d = %lld\n", i, d[i]);
	}
*/

	printf("%lld\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

  scanf("%d %d", &n, &m);
  fi(1, n) {
  	scanf("%d %d", &a[i], &b[i]);
  }
  fi(1, m) {
  	int x, y;
		scanf("%d %d", &x, &y);
		e[x].pb(y);
		e[y].pb(x);
  }
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 22904