#pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
    preprocess() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} ____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main() {
    int n, m;
    cin >> n >> m;
    vi w(n);
    rep(i, n) cin >> w[i];
    vector<pll> vl;
    rep(i, m) {
        int v, l;
        cin >> l >> v;
        vl.emplace_back(v, l);
    }
    sort(all(vl), [](const pll &a, const pll &b) {
        if (a.first == b.first) return a.second > b.second;
        return a.first < b.first;
    });
    if (vl[0].first < *max_element(all(w))) {
        cout << -1 << '\n';
        return 0;
    }
    ll now = 0;
    rep(i, m) {
        chmax(now, vl[i].second);
        vl[i].second = now;
    }
    vi perm(n);
    iota(all(perm), 0);
    ll ans = LINF;
    do {
        vll wnow(n);
        rep(i, n) {
            wnow[i] = w[perm[i]];
        }
        vll dist(n);
        rep(r, n) rep(l, r) {
            if (r - l <= 0) continue;
            ll now = 0;
            repi(i, l, r + 1) {
                now += wnow[i];
            }
            auto it = lower_bound(all(vl), pll{now, -1});
            int idx = it - vl.begin() - 1;
            ll limit = 0;
            if (idx >= 0) {
                limit = vl[idx].second;
            }
            repi(i, l + 1, r) {
                limit -= dist[i];
            }
            chmax(dist[r], limit);
        }
        ll res = 0;
        rep(i, n) {
            res += dist[i];
        }
        chmin(ans, res);

    } while (next_permutation(all(perm)));
    cout << ans << '\n';
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<n+1;++i)

int main(){
    int N,K,sum=0;
    cin >> N >> K;

    rep(i,N){
        rep(j,K){
            sum+=100*i +j;
        }
    }
    cout << sum <<endl;
    return 0;
}