#include <bits/stdc++.h>
using namespace std;
string alpha = "abcdefghijklmnopqrstuvwxyz";
const long long mod = 998244353;
const long long inf = 2e18 + 5;
const long long nax = 101010;
long long n, m;
vector<long long> k;
map<long long, set<long long>> d;
long long S = 0;
bool p(long long x) {
  vector<long long> test(x + 1);
  for (long long i = (1); i < (n + 1); i++) {
    long long idx = (*d[i].lower_bound(-x));
    if (d[i].lower_bound(-x) == d[i].end()) continue;
    test[-idx] += k[i];
  }
  long long blur = 0;
  long long bt = 0;
  for (long long i = (1); i < (x + 1); i++) {
    blur++;
    if (test[i] <= blur) {
      bt += test[i];
      blur -= test[i];
    } else {
      bt += blur;
      blur = 0;
    }
  }
  long long nbt = S - bt;
  long long cst = bt + 2 * nbt;
  return cst <= x;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  k.push_back(0);
  for (long long i = (0); i < (n); i++) {
    long long x;
    cin >> x;
    k.push_back(x);
    S += x;
  }
  for (long long i = (0); i < (m); i++) {
    long long _d, _t;
    cin >> _d >> _t;
    d[_t].insert(-_d);
  }
  if (p(1) == true) {
    cout << 1 << '\n';
  }
  long long high = 1e7;
  long long low = 0;
  while (high - low > 1) {
    long long mid = (high + low) / 2;
    bool p1 = p(mid);
    bool p2 = p(mid + 1);
    if (p1 == false && p2 == true) {
      cout << mid + 1;
      return 0;
    } else if (p1 == false && p2 == false) {
      low = mid;
    } else {
      high = mid;
    }
  }
  return 0;
}
