#include <bits/stdc++.h>
using namespace std;
long long n, m, a[5015], c[5015], p[5015], f[5015][5015], q[5015], pre[5015];
pair<long long, long long> P[5015];
signed main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  memset(f, 0x3f, sizeof f);
  f[0][0] = 0;
  sort(a + 1, a + n + 1);
  for (long long i = 1; i <= m; i++)
    scanf("%lld%lld", &P[i].first, &P[i].second);
  sort(P + 1, P + m + 1);
  for (long long i = 1; i <= m; i++) p[i] = P[i].first, c[i] = P[i].second;
  long long Ssum = 0;
  for (long long i = 1; i <= m; i++) Ssum += c[i];
  if (Ssum < n) return puts("-1"), 0;
  for (long long j = 1; j <= m; j++) {
    long long l = 1, r = 0;
    f[0][j] = q[++r] = 0;
    for (long long i = 1; i <= n; i++) {
      pre[i] = pre[i - 1] + abs(a[i] - p[j]);
      while (i - c[j] > q[l]) l++;
      f[i][j] = min(f[i][j - 1], f[q[l]][j - 1] - pre[q[l]] + pre[i]);
      while (l <= r && f[i][j - 1] - pre[i] <= f[q[r]][j - 1] - pre[q[r]]) r--;
      q[++r] = i;
    }
  }
  printf("%lld\n", f[n][m]);
  return 0;
}
