//https://atcoder.jp/contests/abc183/tasks/abc183_c
//C - Travel
#include <bits/stdc++.h>

using namespace std;

const int MAXN=10;
int nums[MAXN][MAXN];

int main() {
    int n,k;
    cin>>n>>k;

    int i;
    for (i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) {
            cin>>nums[i][j];
        }
    }

    vector<int> idx(n+2);
    iota(idx.begin(), idx.end(), 0);
    idx[n+1]=1;
    int ans=0;
    do {
        int sum=0;
        for (i=2; i<=n+1; i++) {
            sum+=nums[idx[i-1]][idx[i]];
        }
        if (sum==k) {
            ans++;
        }
    } while (next_permutation(idx.begin()+2, idx.end()-1));

    cout<<ans<<"\n";

    return 0;
}
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
typedef pair<int, int> PR;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}
 

//cout<<""<<endl;
int main(){
  ll N,M;cin>>N>>M;
  vl H(N),W(M);
  rep(i,N)cin>>H[i];
  rep(i,M)cin>>W[i];
  sort(all(H));
  sort(all(W));
  vl wa1(N);
  vl wa2(N);
  wa1[0]=-H[0];
  wa2[0]=H[0];
  for(ll i=1;i<N;i++){
    if(i%2==1){
      wa1[i]=wa1[i-1]+H[i];
      wa2[i]=wa2[i-1]-H[i];
    }
    else{
      wa1[i]=wa1[i-1]-H[i];
      wa2[i]=wa2[i-1]+H[i];
    }
  }
  ll ans=1000000000000000;
  
  rep(i,M){
    ll cnt=0;
    auto iter =  lower_bound(all(H), W[i]);
    ll x= iter-H.begin();
    if(x%2==1){
      cnt+=W[i];
      cnt +=wa1[x-1]+wa2[N-1]-wa2[x-1];
    }
    else{
      cnt-=W[i];
      cnt +=wa1[x-1]+wa2[N-1]-wa2[x-1];
    }
    ans =min(ans,cnt);
  }
  cout<<ans<<endl;
}
  




