#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); }
long long lcm(long long n, long long m) { return (m * n) / gcd(n, m); }
long long dx[] = {1, 0};
long long dy[] = {0, 1};
const long long inf = 1e9 + 10;
const long long INF = 1e18;
long long const N = 2e5 + 10;
long long const M = 5100;
double const PI = acos(-1);
long long const MOD = 998244353;
long long Check(long long n, long long pos) { return n & (1 << pos); }
long long Set(long long n, long long pos) { return n |= (1 << pos); }
long long n, m;
vector<pair<long long, long long> > store;
vector<long long> k;
long long visit[N];
bool check(long long now) {
  memset(visit, 0, sizeof(visit));
  pair<long long, long long> pt = {now, n};
  auto it = upper_bound((store.begin()), (store.end()), pt);
  it--;
  long long pos = it - store.begin();
  vector<pair<long long, long long> > apes;
  for (long long i = pos; i >= 0; i--) {
    long long day = store[i].first;
    long long type = store[i].second;
    if (visit[type] == 0) {
      apes.push_back({day, type});
      visit[type] = 1;
    }
  }
  reverse((apes.begin()), (apes.end()));
  long long taka = 0;
  long long extra = 0;
  long long lastDay = 0;
  for (long long i = 0; i < (long long)apes.size(); i++) {
    long long day = apes[i].first;
    lastDay = day;
    long long type = apes[i].second;
    if (i == 0)
      taka += day;
    else
      taka += day - apes[i - 1].first;
    if (k[type] <= taka)
      taka -= k[type];
    else {
      extra += k[type] - taka;
      taka = 0;
    }
  }
  taka += now - lastDay;
  for (long long i = 0; i < n; i++) {
    if (visit[i] == 0) extra += k[i];
  }
  extra <<= 1;
  if (taka >= extra)
    return true;
  else
    return false;
}
int32_t main() {
  cin >> n >> m;
  k.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> k[i];
  }
  for (long long i = 0; i < m; i++) {
    long long day, type;
    cin >> day >> type;
    type--;
    store.push_back({day, type});
  }
  sort((store.begin()), (store.end()));
  long long res = 1;
  long long left = 1, right = 1e11;
  while (left <= right) {
    long long mid = (left + right) >> 1;
    if (check(mid)) {
      res = mid;
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  cout << res << '\n';
}
