#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long n, m, k[200003];
unordered_map<long long, vector<long long>> dt, td;
bool good(long long x) {
  long long i, j, money = 0;
  long long kc[200003];
  for (i = 1; i <= n; ++i) kc[i] = k[i];
  for (i = 1; i <= x; ++i) {
    ++money;
    for (auto it : dt[i]) {
      auto it2 = upper_bound(td[it].begin(), td[it].end(), x);
      if (td[it].size() == 0 or (it2 == td[it].begin())) continue;
      --it2;
      if (*it2 == i) {
        long long mi = min(money, kc[it]);
        money -= mi;
        kc[it] -= mi;
      }
      if (money == 0) break;
    }
  }
  for (i = 1; i <= n; ++i) money -= 2 * kc[i];
  return (money >= 0);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  td.clear(), dt.clear();
  cin >> n >> m;
  long long i, j;
  for (i = 1; i <= n; ++i) cin >> k[i];
  long long d, t;
  for (i = 1; i <= m; ++i) {
    cin >> d >> t;
    dt[d].push_back(t);
    td[t].push_back(d);
  }
  for (i = 1; i <= n; ++i) sort(td[i].begin(), td[i].end());
  long long s = 1, e = 4e5, mid;
  while (s <= e) {
    mid = s + (e - s) / 2;
    if (mid == s) break;
    if (good(mid))
      e = mid;
    else
      s = mid + 1;
  }
  cout << (good(mid) ? mid : mid + 1LL);
  return 0;
}
