#include<bits/stdc++.h>
#define ll long long
#define N 100010
#define M 100010
using namespace std;
struct EDGE{
	ll u, v;
	ll Next;
}G[M << 1];
ll Head[N];
ll tot = 0;
inline void Add(ll u, ll v)
{
	++ tot;
	G[tot].u = u;
	G[tot].v = v;
	G[tot].Next = Head[u];
	Head[u] = tot;
}
struct Node{
	ll a, b, num;
}E[N];
inline bool cmp(Node x, Node y)
{
	return x.a - x.b < y.a - y.b;
}
ll f[N];
ll b[N];
ll w[N];
inline ll Get(ll u)
{
	return f[u] == u ? u : f[u] = Get(f[u]);
}
bool vis[N];
ll d[N], top;
int main()
{
	ll n, m;
	scanf("%lld%lld", &n, &m);
	for(ll i = 1; i <= n; ++ i)
		scanf("%lld%lld", &E[i].a, &E[i].b);
	for(ll i = 1; i <= m; ++ i)
	{
		ll u, v;
		scanf("%lld%lld", &u, &v);
		Add(u, v);
		Add(v, u);
	}
	for(ll i = 1; i <= n; ++ i)
	{
		E[i].num = i;
		b[i] = E[i].b;
		f[i] = i;
	}
	sort(E + 1, E + n + 1, cmp);
	for(ll i = 1; i <= n; ++ i)
	{
		vis[E[i].num] = true;
		ll sumb = 0;
		top = 0;
		for(ll j = Head[E[i].num]; j; j = G[j].Next)
		{
			ll v = G[j].v;
			if(! vis[v])
				continue;
			ll fv = Get(v);
			if(fv != E[i].num)
			{
				sumb += b[fv];
				d[++ top] = fv;
				f[fv] = E[i].num;
			}
		}
		b[E[i].num] = sumb + E[i].b;
		w[E[i].num] = 1000000000000000;
		for(ll j = 1; j <= top; ++ j)
			w[E[i].num] = min(w[E[i].num], sumb - b[d[j]] + max(w[d[j]] + E[i].b, E[i].a));
		w[E[i].num] = min(w[E[i].num], sumb + max(E[i].a, E[i].b));
	}
	printf("%lld", w[E[n].num]);
	return 0;
}