#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

const int maxn = 112;

int h, w;
int a[maxn][maxn];

int main() {
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cin >> h >> w;
  FOR(i, 1, h) FOR(j, 1, w) cin >> a[i][j];
  int mn = a[1][1];
  FOR(i, 1, h) FOR(j, 1, w) chkmin(mn, a[i][j]);
  int ans = 0;
  FOR(i, 1, h) FOR(j, 1, w) ans += a[i][j] - mn;
  cout << ans;
}

#include<bits/stdc++.h>

using namespace std;
using ll = long long;


int main()
{
    ll N, M; cin >> N >> M;
    vector<ll> h(N), w(M);
    vector<ll> ida(N - 1);
    for(ll i = 0; i < N; i++)cin >> h[i];
    for(ll i = 0; i < M; i++)cin >> w[i];
    sort(h.begin(), h.end());
    for(ll i = 0; i < N - 1; i++)ida[i] = h[i + 1] - h[i];

    vector<ll> est(N), ost(N);
    for(ll i = 0; i < N - 1; i++) {
        if(i % 2 == 0) est[i] = ida[i];
        else ost[i] = ida[i];
    }

    for(ll i = 1; i < N - 1; i++) {
        est[i] += est[i - 1], ost[i] += ost[i - 1];
    }
    est.insert(est.begin(), 0);
    ost.insert(ost.begin(), 0);



    ll nin = 2e9;
    for(auto t : w) {
        ll idx = lower_bound(h.begin(), h.end(), t) - h.begin();
        ll cost = 0;
        if(idx % 2 == 0) {
            cost += h[idx] - t;
            cost += est[idx];
            cost += ost[N-1] - ost[idx];


        } else {
            cost += t - h[idx - 1];
            cost += est[idx - 1];
            cost += ost[N-1] - ost[idx - 1];
        }
        nin = min(nin, cost);
    }
    cout << nin << endl;

}