#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int INF = 1061109567;
const long long LINF = 4557430888798830399LL;
const long long MOD = 1000000007;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const double PI = 3.141592653589793;
inline void fasterios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long n, m, t;
long long Limit[400005];
long long Cursale[400005];
long long CurLimit[400005];
vector<long long> Sale[400005];
int main() {
  cin >> t >> m;
  for (int i = 1; i <= t; i++) {
    cin >> Limit[i];
    n += Limit[i];
  }
  for (int i = 1; i <= m; i++) {
    long long Day, Type;
    cin >> Day >> Type;
    Sale[Day].push_back(Type);
  }
  long long Left = 0;
  long long Right = n;
  while (Left < Right) {
    memset(CurLimit, 0, sizeof(CurLimit));
    long long mid = (Left + Right + 1) >> 1;
    long long curans = 2 * n - mid;
    long long used = 0;
    for (int i = curans; i >= 1; i--) {
      Cursale[i] = 0;
      for (int j = 0; j < Sale[i].size(); j++) {
        long long CurrentUsed =
            min(mid - used, Limit[Sale[i][j]] - CurLimit[Sale[i][j]]);
        CurLimit[Sale[i][j]] += CurrentUsed;
        used += CurrentUsed;
        Cursale[i] += CurrentUsed;
      }
    }
    if (used < mid) {
      Right = mid - 1;
      continue;
    }
    bool flag = 1;
    used = 0;
    for (int i = 1; i <= curans; i++) {
      used += Cursale[i];
      if (used > i) {
        flag = 0;
        break;
      }
    }
    if (flag)
      Left = mid;
    else
      Right = mid - 1;
  }
  cout << 2 * n - Left << '\n';
  return 0;
}
