#include <bits/stdc++.h>
using namespace std;
int n, m, k[200001], tot[200001];
set<int> sale[200001];
long long bs_min() {
  long long b = 0, e = 2 * k[0], cur = (b + e + 1) / 2;
  bool ok;
  while (cur < e) {
    memset(tot, 0, sizeof(tot));
    for (long long i = (1); i < (n + 1); ++i) {
      if (!sale[i].empty() && *sale[i].begin() <= cur) {
        auto it = sale[i].upper_bound(cur);
        it--;
        tot[*it] += k[i];
      }
    }
    int mo = 0, s = k[0];
    for (long long i = (1); i < (cur + 1); ++i) {
      mo++;
      int buy = min(mo, tot[i]);
      mo -= buy;
      s -= buy;
    }
    ok = (2 * s <= mo);
    if (ok) {
      e = cur;
      cur = (b + e + 1) / 2;
    } else {
      b = cur;
      cur = (b + e + 1) / 2;
    }
  }
  return cur;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int d, t;
  k[0] = 0;
  cin >> n >> m;
  for (long long i = (1); i < (n + 1); ++i) {
    cin >> k[i];
    k[0] += k[i];
  }
  for (long long i = (0); i < (m); ++i) {
    cin >> d >> t;
    sale[t].insert(d);
  }
  cout << bs_min() << endl;
  return 0;
}
