#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 10;
struct data {
  int nt, to;
} a[N << 1];
ll A[N], B[N], dp[N], s[N];
int p[N], f[N], vs[N];
int head[N], cnt = 0;

void add(int x, int y) {
  a[++cnt].to = y;
  a[cnt].nt = head[x];
  head[x] = cnt;
}

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

int find(int k) {
  return f[k] == k ? f[k] : f[k] = find(f[k]);
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for(int i = 1; i <= n; ++i) {
    p[i] = f[i] = i;
    scanf("%lld%lld", &A[i], &B[i]);
    s[i] = B[i];
    dp[i] = A[i] = max(A[i] - B[i], 0ll);
  }
  sort(p + 1, p + 1 + n, cmp);
  for(int i = 1, x, y; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    add(x, y), add(y, x);
  }
  for(int o = 1; o <= n; ++o) {
    int u = p[o];
    vs[u] = 1;
    for(int i = head[u]; i; i = a[i].nt) {
      int to = a[i].to;
      if(vs[to]) {
        int fx = find(u), fy = find(to);
        if(fx == fy) continue;
        f[fy] = fx, s[fx] += s[fy];
        dp[fx] = min(dp[fx], max(dp[fy], A[fx] - s[fy]));
      }
    }
  }
  printf("%lld\n", dp[find(1)] + s[find(1)]);
  return 0;
}