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

#define MOD 1000000007
#define MOD9 998244353
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
template<class T> bool chmax(T &x, const T &y){if (x < y) {x = y; return true;} return false;}
template<class T> bool chmin(T &x, const T &y){if (x > y) {x = y; return true;} return false;}
template<class T> bool chgeq(T &x, const T &y){if (x <= y) {x = y; return true;} return false;}
template<class T> bool chleq(T &x, const T &y){if (x >= y) {x = y; return true;} return false;}
template<class T> void print(T x, string end = "\n"){cout << x << end;}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W));
    int minn = 1000;
    int ans = 0;
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            cin >> A[i][j];
            minn = min(minn, A[i][j]);
            ans += A[i][j];
        }
    }
    print(ans - minn * H * W);
}
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7; // 998244353
const ll LINF = LLONG_MAX; // ~ 10^18 ~ 1<<60
const int INF = INT_MAX;
const double PI = acos(-1);



int main(){
	ll n, m; cin >> n >> m;

	vector<ll> h(n);
	vector<ll> w(m);

	rep(i,0,n){
		cin >> h[i];
	}

	rep(i,0,m){
		cin >> w[i];
	}

	sort(all(h));

	vector<ll> L(n, 0);
	vector<ll> R(n, 0);

	for(int i = 0; i <= n - 3; i += 2){
		ll x = abs(h[i] - h[i + 1]);
		L[i] = x;
		L[i + 1] = x;
		if(i != 0){
			L[i] += L[i - 1];
			L[i + 1] += L[i - 1];
		}
	}

	for(int i = n - 1; i >= 1; i -= 2){
		ll x = abs(h[i] - h[i - 1]);
		R[i] = x;
		R[i - 1] = x;
		if(i != n - 1){
			R[i] += R[i + 1];
			R[i - 1] += R[i + 1];
		}
	}

	ll ans = LINF;

	for(int i = 0; i < m; i++){
		ll it = lower_bound(all(h), w[i]) - h.begin();
		ll temp = 0;
		if(it % 2 == 1){
			temp = abs(w[i] - h[it - 1]);
			if(it - 2 >= 0) temp += L[it - 2];
			if(it + 1 < n) temp += R[it + 1];
		}else{
			temp = abs(w[i] - h[it]);
			if(it - 1 >= 0) temp += L[it - 1];
			if(it + 1 < n) temp += R[it + 1];
		}
		ans = min(ans, temp);
	}

	cout << ans << endl;

}