#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], t[N];
vector<int> vec[N];
int n, m, sum;
bool check(int x) {
  memset(t, 0, sizeof t);
  int mon = min(N - 1, x), res = sum;
  for (int i = min(N - 1, x); i; i--) {
    if (mon > i) mon--;
    for (auto j : vec[i]) {
      int buy = min(mon, a[j] - t[j]);
      mon -= buy, x -= buy, res -= buy;
      t[j] += buy;
    }
  }
  return x >= res * 2;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum += a[i];
  int x, y;
  for (int i = 1; i <= m; i++) scanf("%d%d", &x, &y), vec[x].push_back(y);
  int l = 0, r = 1e6, mid, ans;
  while (r >= l) {
    mid = l + r >> 1;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}
