#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Oct 11 23:22:41 JST 2020
 **/

template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }

const Int INF = 1e18;
signed main() {
    Int n, m;
    std::cin >> n >> m;
    std::vector<Int> w(n);
    REP(i, n) std::cin >> w[i];
    std::map<Int, Int> mp;
    mp[0] = 0;
    mp[INF] = INF;
    REP(i, m) {
        Int l, v;
        std::cin >> l >> v;
        if (v < *std::max_element(ALL(w))) {
            std::cout << -1 << std::endl;
            return 0;
        }
        chmax(mp[v], l);
    }
    Int ma = 0;
    for (auto& p : mp) {
        chmax(ma, p.second);
        p.second = ma;
    }
    Int ans = INF;
    std::sort(ALL(w));
    do {
        std::vector<Int> d(n);
        REP(i, 1, n) {
            Int sum = w[i];
            for (Int j = i - 1; j >= 0; j--) {
                sum += w[j];
                auto it = std::prev(mp.lower_bound(sum));
                chmax(d[i], d[j] + it->second);
            }
        }
        chmin(ans, d.back());
    } while (std::next_permutation(ALL(w)));
    std::cout << ans << std::endl;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    vector<int> ws(n);
    for (int i = 0; i < n; i++) {
        cin >> ws[i];
    }

    vector<int> ls(m), vs(m), indices(m);
    for (int i = 0; i < m; i++) {
        cin >> ls[i] >> vs[i];
    }

    if (*max_element(begin(ws), end(ws)) > *min_element(begin(vs), end(vs))) {
        cout << -1 << endl;
        return 0;
    }

    iota(begin(indices), end(indices), 0);
    sort(begin(indices), end(indices), [&](int i, int j) { return vs[i] < vs[j]; });

    map<int, int, greater<int>> map;    // map[x] := 対荷重x以下のパーツの中で最長の長さ
    int max_length = 0;
    map[0] = 0;
    for (int i : indices) {
        max_length = max(max_length, ls[i]);
        map[vs[i]] = max_length;
    }

    vector<int> perm(n);
    iota(begin(perm), end(perm), 0);

    int64_t ans = 1LL << 50;

    do {
        vector<vector<int>> cost(n, vector<int>(n, 0));

        for (int i = 0; i < n; i++) {
            int w_sum = ws[perm[i]];
            for (int j = i + 1; j < n; j++) {
                w_sum += ws[perm[j]];
                cost[i][j] = map.upper_bound(w_sum)->second;
            }
        }
        vector<int> table(n, 0);

        for (int i = n - 1; i >= 0; i--) {
            for (int j = i + 1; j < n; j++) {
                table[i] = max(table[i], cost[i][j] + table[j]);
            }
        }
        ans = min(ans, (int64_t)table[0]);
    } while (next_permutation(begin(perm), end(perm)));

    cout << ans << endl;

    return 0;
}