#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}
template <typename T>
T add(T a, T b, long long m) {
  a += b;
  while (a >= 0) a -= m;
  while (a < 0) a += m;
  return a;
}
template <typename T>
T mul(T a, T b, long long m) {
  return (a * 1ll * b) % m;
}
long long n, m;
const long long N = 4e5 + 5;
long long a[N], vis[N] = {0}, nd[N] = {0};
vector<long long> v[N], cur[N];
long long check(long long mid) {
  memset(vis, 0, sizeof(vis));
  for (long long i = 1; i <= n; i++) nd[i] = a[i];
  for (long long i = 1; i <= 2e5; i++) cur[i].clear();
  for (long long i = mid; i >= 1; i--) {
    for (auto it : v[i]) {
      if (!vis[it]) {
        vis[it] = 1;
        cur[i].push_back(it);
      }
    }
  }
  long long have = 0;
  for (long long i = 1; i <= mid; i++) {
    have++;
    for (auto it : cur[i]) {
      long long p = min(nd[it], have);
      nd[it] -= p;
      have -= p;
    }
  }
  long long rem = 0;
  for (long long i = 1; i <= n; i++) {
    rem += nd[i];
  }
  rem *= 2;
  return (rem <= have);
}
long long naruto(long long lo, long long hi) {
  long long mid = 0, ans = 0;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    if (check(mid)) {
      ans = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= m; i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
  }
  long long ans = naruto(1, 4000);
  cout << ans << endl;
}
