//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(false); cin.tie(0);
#define trav(x,a) for (auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define endl "\n"
#define case(t) cout << "Case #" << (t) << ": "
#define reada(a, n) for (int _i = 0; _i < (n); _i++) read(a[_i])
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;

template<class T> void read(T& x) { cin >> x; }
template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); }
template<class T, size_t U> void read(array<T,U>& x) { for (int i = 0; i < U; i++) read(x[i]); }
template<class T> void read(vector<T>& x) { trav(y, x) read(y); }
template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); }

string to_string(const char& x) { return string(1,x); }
string to_string(const char*& x) { return (string)x; }
string to_string(const string& x) { return x; }
template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); }
template<class T, size_t U> string to_string(const array<T,U>& x) { string ret = ""; for (int i = 0; i < U; i++) ret += (!i ? "" : " ") + to_string(x[i]); return ret; }
template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
template<class T> string to_string(const set<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
void print() { cout << endl; }
template<class T> void pr(const T& x) { cout << to_string(x); }
template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); }

int a[N], b[N];

ll solvePre(int l, int r) {
  deque<int> q;
  ll ret = 0;
  for (int i = r; i >= l-1; i--) {
    if (sz(q) && a[i] + sz(q) == b[q.back()])
      ret += sz(q);
    while (sz(q) && a[i] + sz(q) == b[q.back()])
      q.pop_back();
    q.push_front(i);
  }
  if (sz(q) > 1) {
    print(-1);
    exit(0);
  }
  return ret;
}

void flip(int l, int r) {
  reverse(a + l, a + r + 1);
  reverse(b + l, b + r + 1);
  for (int i = l; i <= r; i++)
    a[i] *= -1, b[i] *= -1;
}

ll solveSuff(int l, int r) {
  flip(l-1, r+1);
  ll ret = solvePre(l, r);
  flip(l-1, r+1);
  return ret;
}

ll solve(int l, int r) {
  for (int i = l; i <= r+1; i++)
    if (a[i] <= b[i])
      return solvePre(l, i-1) + solveSuff(i, r);
  return 0;
}

int main() {
  FIO
  int n, l; read(n, l);
  for (int i = 1; i <= n; i++)
    read(a[i]);
  for (int i = 1; i <= n; i++)
    read(b[i]);
  a[0] = 0, a[n+1] = l+1;
  b[0] = 0, b[n+1] = l+1;
  ll ans = 0;
  for (int i = 1, j = 1; i <= n+1; i++)
    if (a[i] == b[i])
      ans += solve(j, i-1), j = i+1;
  print(ans);
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main(void)
{
    ll N, M;
    cin >> N >> M;
    vector<string> S(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> S[i];
    }

    ll a = 1;
    ll b = 0;
    for (ll i = 1; i < N; i++)
    {
        ll count = 0;
        for (ll j = 0; j < M; j++)
        {  
            if (S[0][j] != S[i][j])
            {
                count ++;
            }
        }
        if (count % 2 == 0)
        {
            a++;
        }
        else
        {
            b++;
        }
    }
    cout << a * b << endl;
}