#include <bits/stdc++.h>
using namespace std;
const int N = 200003;
int n, m, S, k[N], last[N], p[N];
vector<int> offers[2 * N];
bool feasible(int d) {
  for (int i = 0; i < n; i++) p[i] = k[i];
  for (int i = 1; i <= d; i++)
    for (int j : offers[i]) last[j] = i;
  int coin = 0;
  for (int i = 1; i <= d; i++) {
    coin++;
    for (int j : offers[i]) {
      if (last[j] != i) continue;
      int tmp = min(coin, p[j]);
      coin -= tmp;
      p[j] -= tmp;
    }
  }
  int s = 0;
  for (int i = 0; i < n; i++) s += 2 * p[i];
  if (s > coin) return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    S += 2 * k[i];
  }
  for (int i = 0; i < m; i++) {
    int d, t;
    cin >> d >> t;
    t--;
    offers[d].push_back(t);
  }
  int l = 1, r = S + 1, mid = l;
  while (l < r) {
    mid = (l + r) / 2;
    if (feasible(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << r;
}
