#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const long long LINF = INF * 1ll * INF;
const double PI = acos(-1.0);
int a[1005], tmp[1005];
int sum;
vector<int> mt[1005];
int n, m;
bool check(int daycnt) {
  int left = sum;
  int burle = daycnt;
  int cost = 0;
  for (int i = 1; i <= n; i++) tmp[i] = a[i];
  for (int i = min(daycnt, 1000); i; i--) {
    burle = min(burle, i);
    for (int j = 0; j < mt[i].size(); j++) {
      while (tmp[mt[i][j]] && burle) {
        tmp[mt[i][j]]--;
        left--;
        burle--;
        cost++;
      }
    }
  }
  cost += 2 * left;
  if (cost > daycnt) return false;
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  for (int i = 0; i < m; i++) {
    int d, t;
    scanf("%d%d", &d, &t);
    mt[d].push_back(t);
  }
  for (int i = sum; i <= 2 * sum; i++) {
    if (check(i)) {
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}
