#include <bits/stdc++.h>
using namespace std;
int needed[200000 + 1];
bool seen[200000 + 1];
vector<int> offers[200000 + 1];
int n, t;
void read_input() {
  int m;
  scanf("%d%d", &n, &m);
  int ki;
  t = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ki);
    needed[i] = ki;
    t += ki;
  }
  int di, ti;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &di, &ti);
    offers[di].push_back(ti);
  }
}
bool solve(int k_max) {
  memset(seen, false, sizeof(seen));
  int money = k_max;
  int money_left = 0;
  int trans = t;
  for (int day = min(k_max, 200000); 1 <= day; day--) {
    if (day < money) {
      money_left += (money - day);
      money = day;
    }
    for (int o : offers[day]) {
      if (needed[o] == 0 || seen[o]) continue;
      seen[o] = true;
      trans -= min(needed[o], money);
      money = max(0, money - needed[o]);
    }
    if (money <= 0) break;
  }
  if (0 < money) money_left += money;
  trans -= (money_left / 2);
  return trans <= 0;
}
int main() {
  read_input();
  int start = t, m, end = 2 * t;
  while (start < end) {
    m = (start + end) / 2;
    if (solve(m))
      end = m;
    else
      start = m + 1;
  }
  printf("%d\n", end);
  return 0;
}
