#include <bits/stdc++.h>
using namespace std;
long long n, m, xx, yy, l, r, ans, a[200001], d[200001], t[200001];
vector<long long> b[200001];
inline long long read() {
  long long sum = 0, x = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') x = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = sum * 10 + ch - '0';
    ch = getchar();
  }
  return sum * x;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
  return;
}
inline bool cmp(long long x, long long y) { return b[x][d[x]] < b[y][d[y]]; }
inline bool check(long long x) {
  long long c = x, ll = 0;
  for (register long long i = 1; i <= n; ++i) {
    d[i] = b[i].size() - 1;
    for (register long long j = 1; j < b[i].size(); ++j)
      if (b[i][j] > x) {
        d[i] = j - 1;
        break;
      }
  }
  sort(t + 1, t + 1 + n, cmp);
  long long v = 0;
  for (register long long i = 1; i <= n; ++i) {
    long long s = b[t[i]][d[t[i]]] - v;
    if (s >= a[t[i]]) {
      c -= a[t[i]];
      v += a[t[i]];
    } else {
      c -= s;
      v += s;
      ll += a[t[i]] - s;
    }
  }
  c -= ll * 2;
  return (c >= 0);
}
signed main() {
  n = read();
  m = read();
  for (register long long i = 1; i <= n; ++i) {
    t[i] = i;
    a[i] = read();
    b[i].push_back(0);
  }
  for (register long long i = 1; i <= m; ++i) {
    xx = read();
    yy = read();
    b[yy].push_back(xx);
  }
  for (register long long i = 1; i <= n; ++i) sort(b[i].begin(), b[i].end());
  l = 0;
  r = 400001;
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  write(l);
  return 0;
}
