#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
const int N = 1e5 + 5;
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3f; 
using namespace std;

int n, m, a[N], b[N], id[N], pa[N], vis[N];
ll f[N], sum[N]; 
vector<int> g[N], son; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int getf(int x) { return pa[x] == x ? x : pa[x] = getf(pa[x]); }

bool cmp(int x, int y) { return a[x] < a[y]; }

int main()
{
	n = read <int> (), m = read <int> ();
	for(int i = 1; i <= n; i++)
	{
		a[i] = read <int> (), b[i] = read <int> ();
		a[i] = max(a[i] - b[i], 0), id[i] = pa[i] = i; 
	}
	sort(id + 1, id + n + 1, cmp);
	for(int u, v, i = 1; i <= m; i++)
		u = read <int> (), v = read <int> (), g[u].push_back(v), g[v].push_back(u);
	for(int u, i = 1; i <= n; i++)
	{
		son.clear(), u = id[i];
		vis[u] = 1, sum[u] = b[u];
		for(int v, j = 0; j < g[u].size(); j++)
		{
			v = g[u][j]; if(!vis[v] || getf(v) == getf(u)) continue;
			sum[u] += sum[getf(v)], son.push_back(getf(v)), pa[getf(v)] = getf(u); 
		}
		if(!son.size()) { f[u] = a[u] + b[u]; continue; }
		f[u] = INF; 
		for(int v, j = 0; j < son.size(); j++)
			v = son[j], f[u] = min(f[u], sum[u] - sum[v] + max(1ll * a[u], f[v])); 
	}
	printf("%lld\n", f[id[n]]); 
	return 0; 
}