#include <bits/stdc++.h>
using namespace std;
int n, a[200001], c[200001], sum, m, yoy;
struct node {
  int x, y;
} b[200001], d[200001];
bool cmp(node x, node y) { return x.x < y.x; }
bool check(int z) {
  for (int i = 1; i <= n; i++) c[i] = a[i];
  for (int i = 1; i <= n; i++) d[i].x = 0, d[i].y = 0;
  for (int i = 1; i <= m; i++) {
    if (b[i].x <= z) {
      d[b[i].y].x = b[i].x;
      d[b[i].y].y = b[i].y;
    }
  }
  sort(d + 1, d + n + 1, cmp);
  int p = 0, q = 0;
  for (int i = 1; i <= n; i++) {
    if (d[i].x) {
      p += d[i].x - q;
      q = d[i].x;
      if (c[d[i].y] <= p) {
        p -= c[d[i].y];
        c[d[i].y] = 0;
      } else {
        c[d[i].y] -= p;
        p = 0;
      }
    }
  }
  p += z - q;
  for (int i = 1; i <= n; i++) {
    p -= c[i] * 2;
    if (p < 0) return 0;
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  for (int i = 1; i <= m; i++) scanf("%d%d", &b[i].x, &b[i].y);
  sort(b + 1, b + m + 1, cmp);
  int l = sum - 1, r = sum << 2, mid = (l + r) >> 1, ans;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  printf("%d", ans);
  return 0;
}
