#include <bits/stdc++.h>
template <typename T>
inline T &read(T &x) {
  register char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  register bool flag = c == '-';
  x = flag ? 0 : c - '0';
  while ((c = getchar()) >= '0' && c <= '9') (x *= 10) += c - '0';
  if (flag) x = -x;
  return x;
}
const int MAX_N = int(1e4) + 10;
struct Heap {
  int len;
  std::pair<long long, int> a[MAX_N];
  inline void up(int x) {
    int y = x >> 1;
    std::pair<long long, int> tmp = a[x];
    while (y && tmp < a[y]) a[x] = a[y], x = y, y = x >> 1;
    a[x] = tmp;
  }
  inline void down(int x) {
    int y = x << 1;
    std::pair<long long, int> tmp = a[x];
    while (y <= len) {
      if (y < len && a[y + 1] < a[y]) ++y;
      if (a[y] < tmp)
        a[x] = a[y], x = y, y = x << 1;
      else
        break;
    }
    a[x] = tmp;
  }
  inline void push(const std::pair<long long, int> &x) {
    a[++len] = x;
    up(len);
  }
  inline void pop() {
    a[1] = a[len--];
    if (len) down(1);
  }
} mice, hole;
int n, m, tot;
int v[MAX_N], h[MAX_N], c[MAX_N], a[MAX_N];
int cnt[MAX_N];
long long ans = 0LL;
int main() {
  read(n), read(m);
  for (int i = 1; i <= n; ++i) {
    read(v[i]);
    a[++tot] = v[i];
  }
  int sum = 0;
  for (int i = 1; i <= m; ++i) {
    read(h[i]), read(c[i]);
    sum += c[i];
    a[++tot] = h[i];
  }
  if (sum < n) {
    printf("-1\n");
    return 0;
  }
  std::sort(a + 1, a + tot + 1);
  tot = std::unique(a + 1, a + tot + 1) - a - 1;
  for (int i = 1; i <= n; ++i)
    ++cnt[std::lower_bound(a + 1, a + tot + 1, v[i]) - a];
  for (int i = 1; i <= m; ++i)
    cnt[std::lower_bound(a + 1, a + tot + 1, h[i]) - a] -= c[i];
  for (int i = 1; i <= tot; ++i) {
    int s = a[i], op = cnt[i];
    while (op > 0) {
      long long cost = (long long)INT_MAX * 10;
      int ths = op;
      if (hole.len && hole.a[1].first + s < cost) {
        cost = hole.a[1].first + s;
        ths = std::min(ths, hole.a[1].second);
        if ((hole.a[1].second -= ths) == 0) hole.pop();
      }
      op -= ths;
      ans += cost * ths;
      mice.push(std::make_pair(-cost - s, ths));
    }
    while (op < 0) {
      long long cost = 0LL;
      int ths = -op;
      if (mice.len && mice.a[1].first + s < cost) {
        cost = mice.a[1].first + s;
        ths = std::min(ths, mice.a[1].second);
        if ((mice.a[1].second -= ths) == 0) mice.pop();
      }
      op += ths;
      ans += cost * ths;
      hole.push(std::make_pair(-cost - s, ths));
    }
  }
  std::cout << ans << "\n";
}
