#include <bits/stdc++.h>
using namespace std;
long long n;
bool check(vector<long long> k, vector<pair<long long, long long> > offers,
           long long days) {
  long long i, j;
  long long cash = 0;
  long long currDay = 0;
  for (auto i : offers) {
    if (i.first > days) break;
    cash += (i.first - currDay);
    long long &rem = k[i.second];
    currDay = i.first;
    long long x = min(rem, cash);
    rem -= x;
    cash -= x;
  }
  cash += days - currDay;
  for (i = 0; i < n; i++) {
    long long req = 2 * k[i];
    if (req > cash) return false;
    cash -= req;
  }
  return true;
}
int32_t main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j;
  long long m;
  cin >> n >> m;
  vector<long long> k(n);
  for (i = 0; i < n; i++) cin >> k[i];
  vector<long long> offers[n];
  long long lav[n];
  memset(lav, -1, sizeof(lav));
  for (i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    offers[y - 1].push_back(x);
  }
  for (i = 0; i < n; i++) sort(offers[i].begin(), offers[i].end());
  long long left = 0;
  long long right = 1e8;
  while (left < right) {
    vector<pair<long long, long long> > temp;
    long long mid = (left + right) / 2;
    for (i = 0; i < n; i++) {
      long long y = upper_bound(offers[i].begin(), offers[i].end(), mid) -
                    offers[i].begin();
      y--;
      if (y >= 0 && y < offers[i].size())
        temp.push_back(make_pair(offers[i][y], i));
    }
    sort(temp.begin(), temp.end());
    if (check(k, temp, mid))
      right = mid;
    else
      left = mid + 1;
  }
  cout << left << "\n";
  return 0;
}
