#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 10;
const long long inf = 1e18;
int x[maxn];
pair<int, int> h[maxn];
long long dp[maxn][maxn], sum[maxn];
int pre[maxn], dis[maxn], q[maxn];
int main() {
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> x[i];
  for (int i = 1; i <= m; i++) cin >> h[i].first >> h[i].second;
  sort(x + 1, x + 1 + n);
  sort(h + 1, h + 1 + m);
  for (int i = 0; i <= m; i++) {
    if (i) pre[i] = pre[i - 1] + h[i].second;
    for (int j = 0; j <= n; j++) dp[i][j] = inf;
  }
  dp[0][0] = 0;
  for (int i = 1; i <= m; i++) {
    sum[0] = 0;
    for (int j = 1; j <= n; j++) {
      dis[j] = abs(x[j] - h[i].first);
      sum[j] = sum[j - 1] + dis[j];
    }
    int head = 1, tail = 0;
    int now = 0;
    for (int j = 0; j <= n; j++) {
      int l = j - min(j, h[i].second);
      while (head <= tail && q[head] < l) head++;
      while (head <= tail &&
             (dp[i - 1][q[tail]] + sum[j] - sum[q[tail]]) >= dp[i - 1][j])
        tail--;
      q[++tail] = j;
      if (head <= tail) dp[i][j] = dp[i - 1][q[head]] + sum[j] - sum[q[head]];
    }
  }
  if (dp[m][n] >= inf) dp[m][n] = -1;
  cout << dp[m][n] << "\n";
}
