#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int ddx[] = {-1, -2, 1, -2, 2, -1, 2, 1}, ddy[] = {-2, -1, -2, 1, -1, 2, 1, 2};
int cnt[200001];
int a[200001], b[200001];
vector<int> v[200001];
int n, m, tot;
bool ok(int k) {
  for (int(i) = (1); (i) <= (n); (i) += (1)) b[i] = a[i];
  vector<pair<int, int> > vv;
  for (int(i) = (1); (i) <= (n); (i) += (1)) {
    int t = upper_bound(v[i].begin(), v[i].end(), k) - v[i].begin() - 1;
    if (v[i][t] != -1) vv.push_back(make_pair(v[i][t], i));
  }
  vv.push_back(make_pair(0, -1));
  sort(vv.begin(), vv.end());
  int buy = 0, money = 0, pr = 0;
  for (int(i) = (1); (i) <= ((int)vv.size() - 1); (i) += (1)) {
    money += vv[i].first - pr;
    pr = vv[i].first;
    int t = min(b[vv[i].second], money);
    b[vv[i].second] -= t, money -= t;
    buy += t;
  }
  money += k - pr;
  return money >= 2 * (tot - buy);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int(i) = (1); (i) <= (n); (i) += (1)) scanf("%d", a + i);
  tot = accumulate(a + 1, a + n + 1, 0);
  for (int(i) = (1); (i) <= (m); (i) += (1)) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[y].push_back(x);
  }
  for (int(i) = (1); (i) <= (n); (i) += (1)) {
    v[i].push_back(-1);
    sort(v[i].begin(), v[i].end());
  }
  int l = 1, r = 400000;
  while (l <= r) {
    int k = l + r >> 1;
    if (ok(k))
      r = k - 1;
    else
      l = k + 1;
  }
  printf("%d", l);
}
