#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#define LL long long
#define PII pair<int,int>
#define x first
#define y second
using namespace std;

constexpr const int N = 2e5 + 10;

int n, w;
int a[N], b[N];
LL s[N], ss[N], ans = 0x7fffffffffffffff;
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    cin >> n >> w;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= w; ++i) cin >> b[i];

    sort(a + 1, a + 1 + n);

    for(int i = 3; i <= n; i += 2) s[i] = s[i - 2] + abs(a[i - 1] - a[i - 2]);
    for(int i = n - 2; i >= 1; i -= 2) ss[i] = ss[i + 2] + abs(a[i + 1] - a[i + 2]);

    for(int i = 1; i <= w; i++)
    {
        int pos = lower_bound(a + 1, a + 1 + n, b[i]) - a;
        if(pos % 2 == 0) pos--;
        ans = min(ans, s[pos] + ss[pos] + abs(b[i] - a[pos]));
    }
    
    cout << ans;

    return 0;
}
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

struct Info{
	Info(){

		len = value = 0;
	}
	Info(ll arg_len,ll arg_value){
		len = arg_len;
		value = arg_value;
	}
	bool operator<(const struct Info& arg) const{

		return len < arg.len;
	}
	ll len,value;
};

ll W[10];
Info info[SIZE];


int main(){

	ll N,M;
	scanf("%lld %lld",&N,&M);

	ll max_W = 0;

	for(ll i = 0; i < N; i++){

		scanf("%lld",&W[i]);
		max_W = max(max_W,W[i]);
	}

	for(ll i = 0; i < M; i++){

		scanf("%lld %lld",&info[i].len,&info[i].value);
		if(max_W > info[i].value){

			printf("-1\n");
			return 0;
		}
	}

	/*
	 * 自分以下の耐荷重で、より長い橋があったら不可
	 * →長さの降順に見て、過去最少の耐荷重ならOK
	 * */

	sort(info,info+M);

	vector<Info> V;

	ll mini = HUGE_NUM;
	for(ll i = M-1; i >= 0; i--){
		if(info[i].value < mini){
			mini = info[i].value;
			V.push_back(info[i]);
		}
	}

	reverse(V.begin(),V.end());

	vector<int> vec;
	for(int i = 0; i < N; i++){

		vec.push_back(i);
	}

	ll ans = HUGE_NUM;

	do{ //ラクダの並び順を全探索

		ll work[N];
		ll rui[N];

		for(ll i = 0; i < N; i++){

			rui[i] = W[vec[i]];
			if(i > 0){

				rui[i] += rui[i-1];
			}
			work[i] = -1;
		}

		work[0] = 0;
		for(int i = 1; i < N; i++){
			for(int head = 0; head <= i-1; head++){	//一団となる先頭のラクダ

				ll tmp_W;

				if(head == 0){

					tmp_W = rui[i];
				}else{

					tmp_W = rui[i]-rui[head-1];
				}

				//tmp_Wで崩壊する、最長の長さの橋を二分探索
				int left = 0,right = V.size()-1,mid = (left+right)/2;
				int max_len = -1;

				while(left <= right){
					if(V[mid].value < tmp_W){

						max_len = V[mid].len;
						left = mid+1;
					}else{

						right = mid-1;
					}
					mid = (left+right)/2;
				}

				if(max_len == -1){ //崩落しない

					work[i] = max(work[i],work[head]);

				}else{

					work[i] = max(work[i],work[head]+max_len);
				}
			}
		}

		ans = min(ans,work[N-1]);

	}while(next_permutation(vec.begin(),vec.end()));

	printf("%lld\n",ans);

	return 0;
}

