#include <bits/stdc++.h>
using namespace std;
void file(bool opt) {
  if (opt && fopen("in.txt", "r")) {
    freopen("in.txt", "r", stdin);
  }
}
int n, m;
int sum = 0;
int r = 0;
int a[200000 + 5];
vector<int> que[200000 + 5];
int s[400000 + 5];
bool check(int up) {
  for (int i = 1; i <= up; i++) s[i] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = que[i].size() - 1; j >= 0; j--) {
      if (que[i][j] <= up) {
        s[que[i][j]] += a[i];
        break;
      }
    }
  }
  int now = 0, buy = 0;
  for (int i = 1; i <= up; i++) {
    now++;
    buy += min(now, s[i]);
    now -= min(now, s[i]);
  }
  return now >= 2 * (sum - buy);
}
int main() {
  file(1);
  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++) {
    int d, t;
    scanf("%d%d", &d, &t);
    que[t].push_back(d);
  }
  for (int i = 1; i <= n; i++) sort(que[i].begin(), que[i].end());
  r = sum << 1;
  int l = 0;
  while (l + 1 < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%d\n", r);
  return 0;
}
