#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;

int n,i,j,k,l,m,sum;
ll s[2];
char st[21];

int main()
{
	#ifdef file
	freopen("a.in","r",stdin);
	#endif
	
	scanf("%d%d",&n,&m);
	fo(i,1,n)
	{
		scanf("%s",st+1),sum=0;
		fo(j,1,m) sum+=st[j]=='1';
		++s[sum&1];
	}
	printf("%lld\n",s[0]*s[1]);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;  
using ll = long long;
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
// #define _GLIBCXX_DEBUG
template <class T> using V = vector<T>;
#define ALL(v) (v).begin(),(v).end()
#define endl '\n'
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
// const ll MOD = 1000000007LL;
const ll MOD = 998244353LL;
const ll INF = 1LL << 60;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const int dy2[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dx2[] = {1, 1, 0, -1, -1, -1, 0, 1};
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
 
/*--------------------------------------------------------------------------------
--------------------------------------------------------------------------------*/

int main(){
    ll n, m;
    cin >> n >> m;
    V<ll> h(n), w(m);
    rep(i, 0, n) cin >> h[i];
    sort(ALL(h));
    rep(i, 0, m) cin >> w[i];
    V<ll> l(n), r(n);
    rep(i, 2, n){
        if(i%2 == 0){
            l[i]+=h[i-1]-h[i-2];
            l[i]+=l[i-2];
        }
    }
    repr(i, 0, n-2){
        if(i%2==0){
            r[i]+=h[i+2]-h[i+1];
            r[i]+=r[i+2];
        }
    }
    // rep(i, 0, n) cout << l[i] << " \n"[i==n-1];
    // rep(i, 0, n) cout << r[i] << " \n"[i==n-1];
    ll ans = INF;
    rep(i, 0, m){
        ll id = lower_bound(ALL(h), w[i]) - h.begin();
        // cout << w[i] << " " << id << endl;
        if(id == 0){
            chmin(ans, abs(h[0]-w[i])+r[0]);
        }else if(id == n){
            chmin(ans, abs(h[n-1]-w[i])+l[n-1]);
        }else{
            if(id%2==0){
                chmin(ans, l[id]+r[id]+abs(h[id]-w[i]));
            }else{
                chmin(ans, l[id-1]+r[id-1]+abs(h[id-1]-w[i]));
            }
        }
    }
    cout << ans << endl;

    return 0;
}