#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    a[i] = in();
    sum += a[i];
  }
  vector<set<int>> ds(n);
  for (int i = 0; i < m; ++i) {
    int p = in() - 1, q = in() - 1;
    ds[q].insert(p);
  }
  int ok = 2 * sum, ng = sum - 1;
  while (ok - ng > 1) {
    int x = (ok + ng) / 2;
    vector<int> p(x);
    for (int i = 0; i < n; ++i) {
      auto itr = ds[i].lower_bound(x);
      if (itr == ds[i].begin()) continue;
      itr--;
      p[*itr] += a[i];
    }
    int cnt = 0;
    for (int i = 0; i < x; ++i) {
      int r = min(p[i], i + 1 - cnt);
      cnt += r;
    }
    if (cnt + 2 * (sum - cnt) <= x)
      ok = x;
    else
      ng = x;
  }
  cout << ok << endl;
  return 0;
}
