#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
vector<int> v[maxn];
int a[maxn];
int b[maxn];
int tot = 0;
int n;
bool check(int x) {
  int cnt = tot;
  int day = x;
  for (int i = 1; i <= n; i++) b[i] = a[i];
  int yu = 0;
  for (int i = min(200000, x); i >= 1; i--) {
    if (v[i].size())
      for (int it : v[i]) {
        while (b[it] && day) {
          day--;
          b[it]--;
          cnt--;
        }
      }
    while (day >= i) {
      day--;
      yu++;
    }
  }
  return yu >= 2 * cnt;
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), tot += a[i];
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
  }
  int l = tot;
  int r = tot + tot;
  int ans = tot + tot;
  while (l <= r) {
    int mid = l + r >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}
