#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> v(n);
  for (long long c = 0; c < n; c++) cin >> v[c];
  vector<pair<long long, long long> > dop(m);
  for (long long c = 0; c < m; c++) cin >> dop[c].first >> dop[c].second;
  sort(v.begin(), v.end());
  sort(dop.begin(), dop.end());
  vector<long long> dp(n, inf);
  for (long long c = 0; c < m; c++) {
    vector<long long> sum(n + 1), arr(n + 1);
    for (long long i = n - 1; i >= 0; i--) {
      sum[i] = sum[i + 1] + abs(v[i] - dop[c].first);
      arr[i] = (i ? dp[i - 1] : 0) + sum[i];
    }
    deque<pair<long long, long long> > q;
    for (long long i = 0; i < n; i++) {
      while (q.size() && q.back().first >= arr[i]) q.pop_back();
      while (q.size() && q.front().second <= i - dop[c].second) q.pop_front();
      q.push_back({arr[i], i});
      dp[i] = min(dp[i], q.front().first - sum[i + 1]);
    }
  }
  if (dp[n - 1] == inf)
    cout << -1;
  else
    cout << dp[n - 1];
  return 0;
}
