#include <bits/stdc++.h>
using namespace std;
static const int N = 1005;
static const int MAX_N = 2e5 + 5;
int a[N], b[N];
int n;
bool judge(int x, int cnt, vector<int> vec[]) {
  int day = x;
  for (int i = 1; i <= n; ++i) b[i] = a[i];
  int cur = 0;
  for (int i = x; i >= 1; --i) {
    for (int j = 0; j < vec[i].size(); ++j) {
      int t = vec[i][j];
      while (b[t] && day) {
        --b[t];
        --cnt;
        --day;
      }
    }
    if (day >= i) {
      ++cur;
      --day;
    }
  }
  return cur >= 2 * cnt;
}
void solve() {
  int m;
  while (scanf("%d%d", &n, &m) != EOF) {
    int cnt = 0;
    vector<int> vec[N << 1];
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &a[i]);
      cnt += a[i];
    }
    for (int i = 0; i < m; ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      vec[u].push_back(v);
    }
    int l = cnt, r = cnt << 1;
    int ans = 0;
    while (l <= r) {
      int m = l + r >> 1;
      if (judge(m, cnt, vec)) {
        r = m - 1;
        ans = m;
      } else
        l = m + 1;
    }
    printf("%d\n", ans);
  }
}
int main() {
  solve();
  return 0;
}
