#include <bits/stdc++.h>
using namespace std;
long long n, m, x[5005], dp[5005][5005], sum[5005], s[5005], q[5010], l, r;
struct Holes {
  long long p;
  long long c;
} h[5005];
bool cmp(Holes a, Holes b) { return a.p < b.p; }
int main() {
  cin >> n >> m;
  memset(dp, 2333333333333333, sizeof(dp));
  dp[0][0] = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> x[i];
  }
  for (long long i = 1; i <= m; i++) {
    cin >> h[i].p >> h[i].c;
  }
  sort(x + 1, x + n + 1);
  sort(h + 1, h + m + 1, cmp);
  for (long long i = 1; i <= m; i++) {
    s[i] = s[i - 1] + h[i].c;
  }
  if (s[m] < n) {
    cout << -1;
    return 0;
  }
  for (long long i = 1; i <= m; i++) {
    dp[i][0] = l = r = 0;
    q[r++] = 0;
    for (long long j = 1; j <= n && j <= s[i]; j++) {
      dp[i][j] = dp[i - 1][j];
      sum[j] = sum[j - 1] + abs(x[j] - h[i].p);
      while ((j - q[l] > h[i].c) ||
             l <= r && dp[i - 1][q[l]] - sum[q[l]] > dp[i - 1][j] - sum[j]) {
        l++;
      }
      q[r++] = j;
      dp[i][j] = min(dp[i][j], dp[i - 1][q[l]] + sum[j] - sum[q[l]]);
    }
  }
  cout << dp[m][n];
  return 0;
}
