#include <bits/stdc++.h>
using namespace std;
int n, m, sum, cnt, ans, x, y;
int a[200005], b[200005];
vector<int> v[200005];
bool check(int mid, int s) {
  cnt = 0;
  for (int i = 1; i <= n; i++) b[i] = a[i];
  for (int i = mid; i >= 1; i--) {
    for (int j = 0; j < v[i].size(); j++) {
      while (b[v[i][j]] && mid) {
        mid--;
        s--;
        b[v[i][j]]--;
      }
    }
    if (mid >= i) {
      mid--;
      cnt++;
    }
  }
  if (cnt / 2 >= s)
    return true;
  else
    return false;
}
int main() {
  scanf("%d%d", &n, &m);
  sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  while (m--) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
  }
  int st = sum, en = sum * 2, mid = 0;
  while (st <= en) {
    mid = (st + en) / 2;
    if (check(mid, sum)) {
      ans = mid;
      en = mid - 1;
    } else
      st = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}
