#include <bits/stdc++.h>
using namespace std;
vector<long long> d[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  long long n, m, i, k, x, y;
  cin >> n >> m;
  long long a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  vector<pair<long long, long long> > v;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }
  sort(v.begin(), v.end());
  for (auto p : v) {
    x = p.first;
    y = p.second;
    d[y].push_back(x);
  }
  long long b, an;
  long long l = 1, r = 2 * n + 1, mid, ans, t;
  while (l <= r) {
    v.clear();
    mid = (l + r) / 2;
    for (i = 1; i < n + 1; i++) {
      k = 1000000007;
      for (auto z : d[i]) {
        if (z > mid) break;
        k = z;
      }
      v.push_back(make_pair(k, i));
    }
    sort(v.begin(), v.end());
    b = 0;
    an = 0;
    k = 0;
    for (auto p : v) {
      x = p.first;
      y = p.second;
      if (x == 1000000007) {
        an += (2 * a[y - 1]);
        continue;
      }
      b += (x - k);
      if (a[y - 1] <= b) {
        b -= a[y - 1];
        an += a[y - 1];
      } else {
        t = a[y - 1] - b;
        an += b;
        b = 0;
        an += (2 * t);
      }
      k = x;
    }
    ans = an;
    if (an > mid) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  long long j;
  for (j = ans; j > 0; j--) {
    v.clear();
    for (i = 1; i < n + 1; i++) {
      k = 1000000007;
      for (auto z : d[i]) {
        if (z > j) break;
        k = z;
      }
      v.push_back(make_pair(k, i));
    }
    sort(v.begin(), v.end());
    b = 0;
    an = 0;
    k = 0;
    for (auto p : v) {
      x = p.first;
      y = p.second;
      if (x == 1000000007) {
        an += (2 * a[y - 1]);
        continue;
      }
      b += (x - k);
      if (a[y - 1] <= b) {
        b -= a[y - 1];
        an += a[y - 1];
      } else {
        t = a[y - 1] - b;
        an += b;
        b = 0;
        an += (2 * t);
      }
      k = x;
    }
    if (an > j) break;
  }
  cout << j + 1;
  return 0;
}
