#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m;
int a[N], b[N], late[N];
struct node {
  int d, t;
  bool operator<(const node &x) const { return d < x.d; }
} s[N];
bool check(int mid) {
  int money = 0, sum = 0, last = 0;
  for (int i = 1; i <= n; i++) {
    b[i] = a[i];
    sum += b[i];
    late[i] = 0;
  }
  for (int i = 1; i <= m; i++)
    if (s[i].d <= mid) late[s[i].t] = max(late[s[i].t], s[i].d);
  for (int i = 1; i <= m; i++) {
    if (s[i].d > mid) break;
    last = s[i].d;
    int d = s[i].d - s[i - 1].d, t = s[i].t;
    money += d;
    if (late[s[i].t] > s[i].d) continue;
    if (money >= b[t]) {
      money -= b[t];
      sum -= b[t];
      b[t] = 0;
    } else {
      sum -= money;
      money = 0;
    }
  }
  if (money + mid - last >= sum * 2)
    return true;
  else
    return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) scanf("%d%d", &s[i].d, &s[i].t);
  sort(s + 1, s + 1 + m);
  int l = 1, r = 4e5, ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}
