#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 212345;
int n, m;
int qt[N];
vector<int> promo[N], days[N];
int la[N], cur[N];
int check(int x) {
  memset(cur, 0, sizeof cur);
  for (int i = 1; i <= n; i++) cur[i] = qt[i];
  int money = 0;
  for (int i = 1; i <= x; i++) {
    money++;
    if (i > 200000) continue;
    for (int t : promo[i]) {
      auto it = upper_bound(days[t].begin(), days[t].end(), i);
      if (it == days[t].end() or *it > x) {
        while (cur[t] > 0 and money > 0) {
          cur[t]--;
          money--;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    money -= cur[i] * 2;
  }
  return money >= 0;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> qt[i];
  for (int i = 0; i < m; i++) {
    int d, t;
    cin >> d >> t;
    promo[d].emplace_back(t);
    days[t].emplace_back(d);
  }
  for (int i = 1; i <= n; i++) sort(days[i].begin(), days[i].end());
  int l = 1;
  int h = 400001;
  while (l < h) {
    int mid = (l + h) / 2;
    if (check(mid)) {
      h = mid;
    } else {
      l = mid + 1;
    }
  }
  assert(l != 400001);
  cout << l << endl;
  return 0;
}
