#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int rd() {
  int sum = 0, flag = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 1) + (sum << 3) + ch - '0';
    ch = getchar();
  }
  return sum * flag;
}
long long RD() {
  long long sum = 0, flag = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 1) + (sum << 3) + ch - '0';
    ch = getchar();
  }
  return sum * flag;
}
struct node {
  long long d, t;
} arr[200010];
long long N[200010];
long long n, m, all;
bool cmp(node a, node b) { return a.d < b.d; }
bool check(long long day) {
  map<long long, long long> tran;
  for (long long i = 1; i <= m; i++) {
    if (arr[i].d > day) break;
    tran[arr[i].t] = arr[i].d;
  }
  long long tot = all;
  long long now = 0;
  long long j = 1;
  for (long long i = 1; i <= day; i++) {
    now++;
    for (; j <= m; j++) {
      if (arr[j].d > i) break;
      if (arr[j].d != i) continue;
      if (arr[j].d == tran[arr[j].t]) {
        tran[arr[j].t] = 0;
        if (now > N[arr[j].t]) {
          now -= N[arr[j].t];
          tot -= N[arr[j].t];
        } else {
          tot -= now;
          now = 0;
          break;
        }
      }
    }
  }
  if (now >= tot * 2)
    return 1;
  else
    return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> N[i];
    all += N[i];
  }
  for (long long i = 1; i <= m; i++) {
    cin >> arr[i].d >> arr[i].t;
  }
  sort(arr + 1, arr + 1 + m, cmp);
  long long l = all;
  long long r = all * 2;
  long long re;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid)) {
      r = mid - 1;
      re = mid;
    } else
      l = mid + 1;
  }
  cout << re << endl;
  return 0;
}
