#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();
  vector<ll> A(N); REP(i, N) A[i] = nextLong();
  sort(ALL(A));
  reverse(ALL(A));

  ll ans = 0;
  ll S = 0;
  for (int i = 0; i < N; i++) {
    ans += S - i * A[i];
    S += A[i];
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<ll> H(n), W(m);
  rep(i, n) cin >> H[i];
  sort(all(H));
  rep(i, m) cin >> W[i];
  vector<ll> suml(n+1), sumr(n+1);
  rep(i, n) {
    suml[i+1] += suml[i];
    if(i%2) suml[i+1] += H[i]-H[i-1];
  }
  rrep(i, n) {
    sumr[i] += sumr[i+1];
    if(i%2) sumr[i] += H[i+1]-H[i];
  }
  ll ans = longinf;
  rep(i, m) {
    int j = lower_bound(all(H), W[i]) - begin(H);
    if(j%2) {
      chmin(ans, W[i]-H[j-1]+suml[j-1]+sumr[j]);
    } else {
      chmin(ans, H[j]-W[i]+suml[j]+sumr[j+1]);
    }
  }
  cout << ans << endk;
  return 0;
}
