#include <bits/stdc++.h>
using namespace std;
const int N = 440000;
int aa[N], a[N], n, m, sum, l, r;
vector<int> day[N];
inline bool check(int x) {
  int rest = x;
  int num = 0;
  for (int i = 1; i <= n; ++i) aa[i] = a[i];
  for (int i = x; i >= 1; --i) {
    for (int j = 0; j < (int)day[i].size(); ++j) {
      int v = day[i][j];
      int buy = min(aa[v], rest);
      aa[v] -= buy;
      rest -= buy;
      num += buy;
    }
    if (rest >= i) rest--;
  }
  int sum1 = 0;
  for (int i = 1; i <= n; ++i) sum1 += aa[i];
  return sum1 * 2 <= x - num;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  int x, y;
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d", &x, &y);
    day[x].push_back(y);
  }
  l = sum;
  r = 2 * sum;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}
