#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
int n, m, c, d, t, Total;
int req[200007];
map<int, vector<int> > sale;
bool check(int days) {
  int temp[n + 1];
  for (int i = 0; i < n + 1; i++) temp[i] = req[i];
  int curr = days, spent = days;
  int dummy = Total;
  for (int i = days; i >= 1; i--) {
    curr = min(curr, i);
    if (sale.find(i) != sale.end()) {
      for (auto it : sale[i]) {
        if (curr > 0 && temp[it] > 0) {
          if (temp[it] <= curr) {
            curr -= temp[it];
            spent -= temp[it];
            dummy -= temp[it];
            temp[it] = 0;
          }
          if (temp[it] > curr) {
            spent -= curr;
            temp[it] -= curr;
            dummy -= curr;
            curr = 0;
          }
        }
      }
    }
  }
  if (2 * dummy <= spent) return true;
  return false;
}
const long long Mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> c;
    Total += c;
    req[i] = c;
  }
  for (int i = 0; i < m; i++) {
    cin >> d >> t;
    sale[d].push_back(t);
  }
  int left = 1, right = 1000000;
  int mn = Mod;
  while (left <= right) {
    int mid = (left + right) / 2;
    if (check(mid)) {
      mn = min(mn, mid);
      right = mid - 1;
    } else
      left = mid + 1;
  }
  cout << mn << endl;
  return 0;
}
