#include <bits/stdc++.h>
using namespace std;
long long dp[5005], tmp[5005];
int n, m;
int mice[5005];
struct HH {
  int pos, C;
  bool operator<(const HH &i) const {
    if (pos != i.pos) return pos < i.pos;
    return C > i.C;
  }
} hole[5005];
long long revsum[5005];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &mice[i]);
  sort(mice + 1, mice + n + 1);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &hole[i].pos, &hole[i].C);
  }
  sort(hole + 1, hole + m + 1);
  for (int i = 1; i <= n; i++) dp[i] = 1e18;
  for (int i = 1; i <= m; i++) {
    for (int j = n; j >= 1; j--) {
      revsum[j] = revsum[j + 1] + (long long)abs(hole[i].pos - mice[j]);
      tmp[j] = dp[j - 1] + revsum[j];
    }
    deque<pair<long long, int> > que;
    for (int j = 1; j <= n; j++) {
      while (!que.empty() && que.front().second <= j - hole[i].C)
        que.pop_front();
      while (!que.empty() && que.back().first >= tmp[j]) que.pop_back();
      que.push_back({tmp[j], j});
      dp[j] = min(dp[j], que.front().first - revsum[j + 1]);
    }
  }
  if (dp[n] == 1e18) dp[n] = -1;
  printf("%I64d", dp[n]);
}
