#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> arr;
long long cnt[(int)2e5 + 1];
vector<pair<long long, long long> > off;
bool check(long long x) {
  memset(cnt, 0, sizeof(cnt));
  vector<int> ono(m);
  for (int i = m - 1; i >= 0; i--) {
    if (off[i].first <= x) {
      cnt[off[i].second]++;
      ono[i] = cnt[off[i].second];
    }
  }
  vector<long long> temp = arr;
  long long rem = accumulate(arr.begin(), arr.end(), 0);
  long long burl = 0, prev = 0;
  for (int i = 0; i < m; i++) {
    if (off[i].first > x) {
      burl += x - prev;
      if (burl >= (2 * rem))
        return true;
      else
        return false;
    }
    burl += off[i].first - prev;
    prev = off[i].first;
    if (ono[i] == 1) {
      long long tem = min(burl, temp[off[i].second]);
      burl -= tem;
      temp[off[i].second] -= tem;
      rem -= tem;
    }
  }
  if (x >= prev) {
    burl += x - prev;
    if (burl >= (2 * rem))
      return true;
    else
      return false;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  cin >> n >> m;
  arr.resize(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  off.resize(m);
  for (int i = 0; i < m; i++) {
    cin >> off[i].first >> off[i].second;
    off[i].second -= 1;
  }
  sort(off.begin(), off.end());
  long long beg = 1, last = 4e5;
  while (beg < last) {
    long long mid = (beg + last) / 2;
    if (check(mid))
      last = mid;
    else
      beg = mid + 1;
  }
  cout << last << endl;
  return 0;
}
