#include <bits/stdc++.h>

using namespace std;
#define pii pair <int , int>
#define F first
#define S second
const int N = 1e5 + 5, inf = 1e9 + 1;
int A[N], B[N], par[N], C, n, m;
long long W[N], Sum;
vector <int> g[N];
priority_queue <pii, vector<pii>, greater<pii>> pq[N];

void init() {
    C = n;
    for (int v = 1; v <= n; v++) {
        par[v] = v, W[v] = B[v];
        while (!pq[v].empty()) pq[v].pop();
        for (int u : g[v]) pq[v].push({A[u] - B[u], u});
    }
}
int getpar(int v) {return par[v] = (par[v] == v ? v : getpar(par[v]));}
void Union(int u, int v) {
    u = getpar(u);
    if (u == v) return ;
    par[u] = v, W[v] += W[u], C--;
    if (pq[u].size() > pq[v].size()) swap(pq[u], pq[v]);
    while (!pq[u].empty()) pq[v].push(pq[u].top()), pq[u].pop();
}
bool check(int w) {
    init();
    for (int v = 1; v <= n; v++) if (par[v] == v && w + W[v] >= A[v]) {
        while (!pq[v].empty()) {
            int u = pq[v].top().S;
            if (A[u] - B[u] > W[v] + w) break ;
            pq[v].pop(), Union(u, v);
        }
    }
    return C == 1;
}
int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> A[i] >> B[i], Sum += B[i];
    if (n == 1) return cout << max(A[1], B[1]) << "\n", 0;
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v), g[v].push_back(u);
    }
    int dw = -1, up = inf;
    while (up - dw > 1) {
        int md = (up+dw)>>1;
        if (check(md)) up = md;
        else dw = md;
    }
    cout << Sum + up << "\n";


    return 0;
}
