#include <bits/stdc++.h>
using namespace std;
const long long oo = 1000000000000000000LL;
const int N = 100005;
vector<pair<int, int>> ds;
long long data[2][100005];
int x[N], p[N], c[N], st[N];
long long val[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", x + i);
    ds.push_back({x[i], i});
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", p + i, c + i);
    ds.push_back({p[i], -i});
  }
  sort(ds.begin(), ds.end());
  long long* f[2] = {data[0] + 10005, data[1] + 10005};
  int flag = 0;
  for (int i = -n; i <= n; i++) f[flag][i] = oo;
  f[flag][0] = 0;
  long long last = ds[0].first;
  for (int i = 0; i < ds.size(); i++) {
    int old = flag;
    flag ^= 1;
    if (ds[i].second > 0) {
      f[flag][n] = oo;
      for (int j = -n; j < n; j++) {
        f[flag][j] = oo;
        if (f[old][j + 1] < oo)
          f[flag][j] = f[old][j + 1] + (ds[i].first - last) * abs(j + 1);
      }
    } else {
      int head = 0, tail = -1, cc = c[-ds[i].second];
      for (int j = -n; j <= n; j++) {
        if (f[old][j] < oo) {
          long long tmp = f[old][j] + abs(j) * (ds[i].first - last);
          while (head <= tail && val[tail] > tmp) tail--;
          st[++tail] = j;
          val[tail] = tmp;
        }
        while (head <= tail && st[head] + cc < j) head++;
        f[flag][j] = oo;
        if (head <= tail) f[flag][j] = val[head];
      }
    }
    last = ds[i].first;
  }
  if (f[flag][0] == oo)
    printf("-1");
  else
    printf("%lld", f[flag][0]);
}
