//#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
ll H[200001],W[200001];
ll saleft[200001],saright[200001];
int main(){
	int N,M;
	scan(N>>M);
	rep(i,N) scan(H[i]);
	rep(j,M) scan(W[j]);
	sort(H,H+N);
	sort(W,W+M);
	rep(i,N/2){
		saleft[i+1]=saleft[i]+abs(H[2*i]-H[2*i+1]);
	}
	brep1(i,N/2){
		saright[i-1]=saright[i]+abs(H[2*i]-H[2*i-1]);
	}
	ll ans=INFl;
	rep(j,M){
		int soeji=lower_bound(H,H+N,W[j])-H;
		int iti=soeji/2;
		int taisho=iti*2;
		debug(j,W[j],soeji,iti,taisho);
		debug(H[taisho]);
		ll sum=saleft[iti]+saright[iti]+abs(H[taisho]-W[j]);
		chmin(ans,sum);
	}
	prin(ans);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static int IN(void)
{
  int x=0,f=1,c;while(c=getchar(),c<48||c>57){if(c==45)f=-f;}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f*x;
}
static void OUT(long x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x-x/10*10+48);}
typedef struct List{int nx,v,c,d;}edge;
int hsz=0;long minHeap[200001][2],output[2];
static void PUSH(int id,long key)
{
  int i=++hsz,j=i>>1;long sw[2];
  minHeap[i][0]=id,minHeap[i][1]=key;
  while(j)
  {
    if(minHeap[i][1]<minHeap[j][1])
    {
      sw[0]=minHeap[j][0],sw[1]=minHeap[j][1];
      minHeap[j][0]=minHeap[i][0],minHeap[j][1]=minHeap[i][1];
      minHeap[i][0]=sw[0],minHeap[i][1]=sw[1];
      i=j;j>>=1;
    }else break;
  }
}
static void POP(void)
{
  int i=1,j=i+1;long sw[2];
  output[0]=minHeap[i][0],output[1]=minHeap[i][1];
  minHeap[i][0]=minHeap[hsz][0],minHeap[i][1]=minHeap[hsz--][1];
  while(j<=hsz)
  {
    if(j<hsz&&minHeap[j^1][1]<minHeap[j][1]){j^=1;}
    if(minHeap[j][1]<minHeap[i][1])
    {
      sw[0]=minHeap[j][0],sw[1]=minHeap[j][1];
      minHeap[j][0]=minHeap[i][0],minHeap[j][1]=minHeap[i][1];
      minHeap[i][0]=sw[0],minHeap[i][1]=sw[1];
      i=j;j=i<<1;
    }else break;
  }
  return;
}
int main(void)
{
  int N=IN(),M=IN(),vis[100000],esz=0,adj[100000];
  long dist[100000];edge e[200000];
  rep(i,N){dist[i]=9e18;}
  rep(i,M)
  {
    int A=IN(),B=IN(),C=IN(),D=IN();
    e[2*i].nx=adj[A-1];adj[A-1]=2*i+1;
    e[2*i].v=B;e[2*i].c=C;e[2*i].d=D;
    e[2*i+1].nx=adj[B-1];adj[B-1]=2*i+2;
    e[2*i+1].v=A;e[2*i+1].c=C;e[2*i+1].d=D;
  }
  dist[0]=0l;
  PUSH(1,0l);
  while(hsz)
  {
    POP();
    int u=output[0]-1;long v=output[1];
    if(vis[u]){continue;}
    for(int i=adj[u];i;i=e[i-1].nx)
    {
      int c=e[i-1].c,d=e[i-1].d,to=e[i-1].v;long len=0l;
      if(d)
      {
        int x=sqrt(d)-1;
        if(d/(x+1)>1+d/(x+2)){x++;}
        if(d/(x+1)>1+d/(x+2)){x++;}
        if(v>1l*x){len=1l*c+1l*d/(v+1l);}
        else{len=1l*c+1l*x-v+1l*d/(1l*x+1l);}
      }else{len=1l*c;}
      if(dist[to-1]>v+len){dist[to-1]=v+len;PUSH(to,v+len);}
    }
    vis[u]=1; 
  }
  if(dist[N-1]==9e18){puts("-1");}else OUT(dist[N-1]);
}