#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const int N = 400000 + 100;
const int M = 50000 + 10;
const int MOD = 998244353;
const double PI = acos(-1.0);
int n, m;
int a[N], b[N];
vector<int> ve[N];
bool check(int x, int y) {
  int re = x, flag = 0;
  for (int i = 1; i <= n; i++) b[i] = a[i];
  for (int i = x; i >= 1; i--) {
    for (int j = 0; j < ve[i].size(); j++)
      while (b[ve[i][j]] && re) {
        re--;
        b[ve[i][j]]--;
        y--;
      }
    if (re >= i) {
      re--;
      flag++;
    }
  }
  if (flag / 2 >= y) return 1;
  return 0;
}
int main() {
  int sum = 0, ans = inf;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  for (int i = 1; i <= m; i++) {
    int aa, bb;
    scanf("%d %d", &aa, &bb);
    ve[aa].push_back(bb);
  }
  int l = sum, r = sum * 2;
  while (l <= r) {
    int mid = l + r >> 1;
    if (check(mid, sum)) {
      ans = min(ans, mid);
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}
