#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

int N, M;

int main()
{
    cin >> N >> M;
    int ret = 0;

    auto S = new string[N];
    //auto Sones = new int[N];
    //auto Sbits = new std::bitset<20>[N];
    uint64_t nOdd = 0, nEven = 0;
    for (auto i = 0; i < N; i++)
    {
        cin >> S[i];
        //Sones[i] = std::bitset<20>(S[i]).count();//std::count(S[i].cbegin(), S[i].cend(), '1');
        //Sbits[i] = std::bitset<20>(S[i]);
        if (std::bitset<20>(S[i]).count() % 2 == 0)
        {
            nEven++;
        }
        else
        {
            nOdd++;
        }
    }

    cout << nEven * nOdd << endl;
}

//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<unordered_map>
#define endl                 '\n'
#define PI              	acos(-1.0)
#define pf              	printf
#define sf            		scanf
#define ff 					first
#define ss					second
#define pb 					push_back
#define mk 					make_pair
#define ll 					long long
#define VI              	vector<long long>
#define pr 					pair<long long,long long>

#define sf1(a)              scanf("%d", &a)
#define sf2(a,b)            scanf("%d %d",&a, &b)
#define sf3(a,b,c)          scanf("%d %d %d", &a, &b, &c)

#define sl1(a)              scanf("%I64d", &a)
#define sl2(a,b)            scanf("%I64d %I64d", &a, &b)
#define sl3(a,b,c)			scanf("%I64d %I64d %I64d", &a, &b, &c)

#define SET(a,x)          	memset( a, x,    sizeof(a) )
#define SETV(a,x)         	memset(a.begin(), a.end(),x )
#define REP(i,a,b)       	for(long long i=a;i<b;i++)
#define all(x)              (x).begin(), (x).end()
#define sz(x)      			((int)x.size())
#define tc(cn) 				pf("Case %d: ",cn)

#define M 					10000007
#define INF                 2147483647

#define sqr(x)           	(x)*(x)
#define gcd(a, b)        	__gcd(a, b)
#define lcm(a, b)        	((a)*((b)/gcd(a,b)))

#define fio 				ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
inline void Time() { cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s. \n";}





void solve()
{

	ll n;
	cin >> n;
	VI a(n), b(n), ans;

	for (ll &x : a)cin >> x;
	for (ll &x : b)cin >> x;

	unordered_map<ll, ll>un;
	int count = 0;
	for (int i = 0; i < n; i++)
	{
		ll x = a[i];
		ll y = b[i];

		for (int k = x; k <= y; k++)
		{
			un[k]++;
			if (un[k] == n)count++;
		}

	}

	cout << count << endl;


}

int main()
{	//fio;

solve();


	//pf("\n\n\n\n"); Time();
	return 0;
}
