#include <bits/stdc++.h>
using namespace std;
vector<int> copy1;
vector<int> data_1[(int)3e5];
int data_2[(int)3e5];
int n, m, total;
int func(int day) {
  vector<int> remaining = copy1;
  int t = total;
  int money = day, cur_money = day;
  for (int i = day; i >= 1; i--)
    for (int j = 0; j < data_1[i].size(); j++) {
      cur_money = min(i, cur_money);
      while (remaining[data_1[i][j]] and cur_money)
        remaining[data_1[i][j]]--, t--, money--, cur_money--;
    }
  money -= (t * 2);
  if (money >= 0)
    return 1;
  else
    return 0;
}
int main() {
  cin >> n >> m;
  copy1.resize(n + 1);
  for (int i = (1); i <= (n); i++) cin >> copy1[i], total += copy1[i];
  for (int i = (1); i <= (m); i++) {
    int day, type;
    cin >> day >> type;
    data_1[day].push_back(type);
  }
  for (int i = (1); i <= (2000); i++)
    if (func(i)) return cout << i, 0;
  return 0;
}
