#include <bits/stdc++.h>
using namespace std;
int k[200005];
vector<int> a[400005];
int kk[400005];
int n, m, sum;
bool CheckDay(int mid) {
  int num = sum;
  for (int i = 1; i <= n; ++i) {
    kk[i] = k[i];
  }
  int left = mid;
  int x = 0;
  for (int i = mid; i >= 1 && left; --i) {
    for (int j = 0; j < a[i].size(); ++j) {
      if (!kk[a[i][j]]) continue;
      int buy = min(kk[a[i][j]], left);
      kk[a[i][j]] -= buy;
      num -= buy;
      left -= buy;
    }
    if (left == i) {
      x++;
      left = i - 1;
    }
  }
  return x >= num * 2;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> k[i];
    sum += k[i];
  }
  int d, t;
  for (int i = 0; i < m; ++i) {
    cin >> d >> t;
    a[d].push_back(t);
  }
  int l = sum, r = sum * 2;
  int Day;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (CheckDay(mid)) {
      Day = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << Day << endl;
  return 0;
}
