#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = 0;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = 1;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
int n, m;
int x[5001];
pair<int, int> p[5001];
deque<int> q;
deque<int> sp;
ll now;
ll ans;
ll f[5001];
int main() {
  read(n);
  read(m);
  for (int i = (1); i <= (n); i++) read(x[i]);
  for (int j = (1); j <= (m); j++) {
    read(p[j].first);
    read(p[j].second);
  }
  sort(x + 1, x + n + 1);
  sort(p + 1, p + m + 1);
  int temp = 0;
  for (int i = (1); i <= (m); i++) temp += p[i].second;
  if (temp < n) {
    puts("-1");
    return 0;
  }
  for (int i = (1); i <= (n); i++) f[i] = 1e18;
  for (int i = (1); i <= (m); i++) {
    deque<pair<ll, int> > q;
    q.push_back(make_pair(0, 0));
    ll sum = 0;
    for (int j = (1); j <= (n); j++) {
      sum += abs(p[i].first - x[j]);
      while ((!q.empty()) && (q.back().first >= f[j] - sum)) q.pop_back();
      q.push_back(make_pair(f[j] - sum, j));
      while ((j - q.front().second) > p[i].second) q.pop_front();
      f[j] = q.front().first + sum;
    }
  }
  writeln(f[n]);
}
