#include <bits/stdc++.h>
using namespace std;
vector<int> v[400010];
int a[400010], b[400010];
int tot = 0;
bool func(int mid) {
  int sum = 0;
  int m = mid;
  memset(b, 0, sizeof(b));
  for (int i = mid - 1; i >= 0; i--) {
    if (m > i + 1) m--;
    int len = v[i].size();
    for (int j = 0; j < len; j++) {
      int x = v[i][j];
      int y = min(a[x] - b[x], m);
      m -= y;
      sum += y;
      b[x] += y;
    }
  }
  if (tot * 2 > mid + sum) return false;
  return true;
}
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    tot += a[i];
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    v[x].push_back(y);
  }
  int head = tot;
  int tail = 2 * tot;
  while (head < tail) {
    int mid = (head + tail) / 2;
    if (func(mid))
      tail = mid;
    else
      head = mid + 1;
  }
  printf("%d", head);
  return 0;
}
