#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const ld pi = acos(0) * 2;
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = 0;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = 1;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
int n, m;
int k[200001];
int r[200001];
vector<int> off[400001];
vector<int> best[200001];
bool check(int last) {
  for (int i = (1); i <= (last); i++) off[i].clear();
  for (int i = (1); i <= (n); i++)
    for (int p : best[i])
      if (p <= last) {
        off[p].push_back(i);
        break;
      }
  for (int i = (1); i <= (n); i++) r[i] = k[i];
  int coin = 0;
  for (int i = (1); i <= (last); i++) {
    coin++;
    for (int p : off[i])
      while (coin && r[p]) {
        coin--;
        r[p]--;
      }
  }
  for (int i = (1); i <= (n); i++) coin -= r[i] * 2;
  return (coin >= 0);
}
int main() {
  read(n);
  read(m);
  for (int i = (1); i <= (n); i++) read(k[i]);
  for (int i = (1); i <= (m); i++) {
    int d, t;
    read(d);
    read(t);
    best[t].push_back(d);
  }
  for (int i = (1); i <= (n); i++) sort(best[i].begin(), best[i].end());
  for (int i = (1); i <= (n); i++) reverse(best[i].begin(), best[i].end());
  int low = 1, high = 400000, mid, ans = 0;
  while (low <= high) {
    mid = (low + high) / 2;
    if (check(mid)) {
      ans = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  writeln(ans);
}
