#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

ll dp[1001][1001];

ll get(vector<ll> & a, vector<ll> & b, ll left, ll right) {
  if (left == -1) return right + 1;
  if (right == -1) return left + 1;

  if (dp[left][right] == -1) {
    if (a[left] == b[right])
      dp[left][right] = get(a, b, left-1, right-1);
    else
      dp[left][right] = get(a, b, left-1, right-1) + 1;

    dp[left][right] = min(dp[left][right], get(a, b, left-1, right) + 1);
    dp[left][right] = min(dp[left][right], get(a, b, left, right-1) + 1);
  }

  return dp[left][right];
}

void
solve() {
  ll n, m;
  cin>>n>>m;

  vector<ll> a(n), b(m);
  for (ll i=0; i<n; i++) cin>>a[i];
  for (ll i=0; i<m; i++) cin>>b[i];

  memset(dp, -1, sizeof dp);
  cout<<get(a, b, n-1, m-1)<<endl;
}

int 
main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}


#include <bits/stdc++.h>
#define rei register int
using namespace std;

int main(){
    int n,m;
    int ans=0;
    scanf("%d%d",&n,&m);
    for(rei i=1;i<=n;++i){
        char tmp[22];
        int tmpn=0;
        scanf("%s",tmp);
        for(rei j=0;j<m;++j)
            if(tmp[j]-'0') tmpn++;
        if(tmpn%2) ans++;
    }
    printf("%lld\n",1ll*ans*(n-ans));
    getchar();
    getchar();
    return 0;
}