#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, m;
int a[1005], mp[1005], all, b[1005];
vector<int> v[2000005];
bool check(int x) {
  int now = x;
  int cnt = 0;
  int tmp = 0;
  for (int i = 1; i <= n; i++) {
    b[i] = mp[i];
  }
  for (int i = x; i >= 1; i--) {
    if (v[i].size() != 0) {
      for (int j = 0; j < v[i].size(); j++) {
        while (b[v[i][j]] && now) {
          now--;
          cnt++;
          b[v[i][j]]--;
        }
      }
    }
    if (now >= i) now--, tmp++;
  }
  if (tmp / 2 >= (all - cnt))
    return 1;
  else
    return 0;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    v[i].clear();
    scanf(" %d", &a[i]);
    all += a[i];
    mp[i] = a[i];
  }
  for (int i = 1; i <= m; i++) {
    int d, b;
    scanf("%d %d", &d, &b);
    v[d].push_back(b);
  }
  int l = 1, r = all * 2 + 5;
  int ans;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}
