#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int k[maxn];
pair<int, int> s[maxn];
bool mark[maxn];
int main(int argc, char *argv[]) {
  int n, m, d, t, sum = 0, tans;
  int l, r, mid;
  int rm = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k[i]);
    sum += k[i];
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &d, &t);
    if (k[t]) s[rm++] = {d, t};
  }
  sort(s, s + rm);
  bool getans;
  l = sum;
  r = 2 * sum;
  mid = (l + r) / 2;
  while (l < r) {
    mid = (l + r) / 2;
    tans = 2 * sum - mid;
    memset(mark, 0, sizeof(mark));
    getans = false;
    for (int j = rm - 1; j >= 0; j--) {
      if (tans > s[j].first)
        break;
      else if (s[j].first > mid)
        continue;
      t = s[j].second;
      if (!mark[t]) {
        tans -= k[t];
        mark[t] = true;
      }
      if (tans <= 0) {
        getans = true;
        break;
      }
    }
    if (getans)
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", r);
  return 0;
}
