#include <bits/stdc++.h>
using namespace std;
const long long N = 5005, inf = 1e18 + 9;
long long n, m, x[N], sumc, dp[N][2], las, nex = 1;
pair<long long, long long> p[N];
deque<pair<long long, long long> > dq[2];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) cin >> x[i];
  for (long long i = 1; i <= m; ++i)
    cin >> p[i].first >> p[i].second, sumc += p[i].second;
  if (sumc < n) return cout << -1, 0;
  sort(x + 1, x + n + 1);
  sort(p + 1, p + m + 1);
  for (long long i = 1; i < N; ++i) {
    for (long long j = 0; j < 2; ++j) {
      dp[i][j] = inf;
    }
  }
  for (long long j = 1; j <= m; ++j) {
    long long temp = 0;
    dq[nex].clear();
    dq[nex].push_back(pair<long long, long long>(0, 0));
    for (long long i = 1; i <= n; ++i) {
      temp += abs(x[i] - p[j].first);
      while (!dq[nex].empty() && dq[nex].back().first >= -temp + dp[i][las])
        dq[nex].pop_back();
      dq[nex].push_back(pair<long long, long long>(-temp + dp[i][las], i));
      while (!dq[nex].empty() && dq[nex].front().second < i - p[j].second)
        dq[nex].pop_front();
      dp[i][nex] = dq[nex].front().first + temp;
    }
    swap(las, nex);
  }
  cout << dp[n][las];
  return 0;
}
