#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 2e6 + 100;
const int mod = 998244353;
int n, m;
int k[maxn], tmp[maxn];
vector<int> g[maxn];
bool solve(long long day) {
  long long ccost = day;
  long long cost = min(day, (long long)2e5);
  long long res = 0;
  for (int i = 1; i <= n; i++) tmp[i] = k[i], res += k[i];
  for (int i = min((long long)2e5, day); i >= 1; i--) {
    cost = min(cost, 1LL * i);
    for (auto to : g[i]) {
      if (tmp[to] && cost > 0) {
        if (cost > tmp[to]) {
          cost -= tmp[to];
          res -= tmp[to];
          ccost -= tmp[to];
          tmp[to] = 0;
        } else {
          ccost -= cost;
          tmp[to] -= cost;
          res -= cost;
          cost = 0;
          break;
        }
      }
    }
  }
  if (ccost >= 2 * res)
    return true;
  else
    return false;
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  long long sum = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &k[i]), sum += k[i] * 2;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d", &x);
    scanf("%d", &y);
    g[x].push_back(y);
  }
  long long l = 0, r = sum, ans = 0;
  while (l <= r) {
    int mid = l + r >> 1;
    if (solve(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
