#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long lgput(long long a, long long b, long long mod) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = (ret * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return (ret % mod);
}
inline long long inv(long long x, long long MOD) {
  return lgput(x, MOD - 2, MOD);
}
const long double PI = acos(-1);
const long double eps = 1e-6;
const int inf = 1e9;
const int MAXN = 2e5 + 10;
;
int n, m;
int need[MAXN];
int neednow[MAXN];
vector<int> when[MAXN];
int binarySearch(vector<int> &v, int val) {
  int best = 0;
  for (int step = 20; step >= 0; --step) {
    if (best + (1 << step) < v.size() && v[best + (1 << step)] <= val) {
      best += (1 << step);
    }
  }
  return best;
}
bool ok(int lim) {
  int baniCurenti = 0;
  memcpy(neednow, need, sizeof neednow);
  vector<pair<int, int> > special;
  special.emplace_back(0, -1);
  for (int i = 1; i <= n; ++i) {
    int bs = binarySearch(when[i], lim);
    if (bs) {
      special.emplace_back(when[i][bs], i);
    }
  }
  sort((special).begin(), (special).end());
  for (int i = 1; i < special.size(); ++i) {
    baniCurenti += special[i].first - special[i - 1].first;
    int cumpar = min(baniCurenti, neednow[special[i].second]);
    neednow[special[i].second] -= cumpar;
    baniCurenti -= cumpar;
  }
  baniCurenti += lim - special.back().first;
  for (int i = 1; i <= n; ++i) {
    baniCurenti -= 2 * neednow[i];
  }
  return baniCurenti >= 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(12);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> need[i];
    when[i].emplace_back(0);
  };
  vector<pair<int, int> > off(m);
  for (auto &x : off) cin >> x.first >> x.second;
  sort((off).begin(), (off).end());
  for (auto &x : off) {
    when[x.second].emplace_back(x.first);
  }
  int ans = 0;
  for (int step = 20; step >= 0; --step) {
    if (!ok(ans + (1 << step))) {
      ans += (1 << step);
    }
  }
  cout << ans + 1 << '\n';
  return 0;
}
