#include <bits/stdc++.h>
using namespace std;
struct node {
  long long x, v;
} hole[5003];
bool cmp(node a, node b) { return a.x < b.x; }
long long mice[5003], sum[5003], pre[5003], dp[5003][5003];
const int INF = 0x3f3f3f3f;
int main() {
  int n, m;
  memset(dp, INF, sizeof(dp));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%I64d", &mice[i]);
  for (int i = 1; i <= m; ++i) scanf("%I64d%I64d", &hole[i].x, &hole[i].v);
  sort(mice + 1, mice + n + 1);
  sort(hole + 1, hole + m + 1, cmp);
  for (int i = 1; i <= m; ++i) pre[i] = pre[i - 1] + hole[i].v;
  if (pre[m] < n) {
    puts("-1");
    return 0;
  }
  dp[0][0] = 0;
  for (int i = 1; i <= m; i++) {
    dp[i][0] = 0;
    int l = 0;
    for (int j = 1; j <= pre[i] && j <= n; j++) {
      dp[i][j] = dp[i - 1][j];
      sum[j] = sum[j - 1] + llabs(mice[j] - hole[i].x);
      while (j - l > hole[i].v) ++l;
      while (l < j && sum[j] - sum[l] > dp[i - 1][j] - dp[i - 1][l]) ++l;
      dp[i][j] = min(dp[i][j], (long long)sum[j] + dp[i - 1][l] - sum[l]);
    }
  }
  printf("%I64d\n", dp[m][n]);
}
