#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define Size(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 400010;
int n, m, a[N], b[N], value[N], id[N], fa[N];
vector<int> e[N];
ll f[N], g[N]; bool vis[N];

template<typename T> void gi(T &x) {
	x = 0; register char c = getchar();
	for(; c < '0' || c > '9'; c = getchar());
	for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + (c ^ 48);
}
inline bool cmp(const int &x, const int &y) { return value[x] < value[y]; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main() {
	gi(n), gi(m);
	rep(i, 1, n) gi(a[i]), gi(b[i]), value[i] = max(0, a[i] - b[i]), id[i] = fa[i] = i;
	sort(id + 1, id + n + 1, cmp);
	rep(i, 1, m) { int x, y; gi(x), gi(y), e[x].pb(y), e[y].pb(x); }
	rep(i, 1, n) {
		vector<int> edge; int u = id[i]; vis[u] = 1, g[u] = b[u];
		for(auto v : e[u]) if(vis[v] && find(u) != find(v))
			edge.pb(v), edge.pb(find(v)), g[u] += g[find(v)], fa[find(v)] = u;
		f[u] = g[u] + value[u];
		for(auto v : edge) f[u] = min(f[u], g[u] - g[v] + max(1ll * value[u], f[v]));
	}
	printf("%lld\n", f[id[n]]);
	return 0;
}