#include<bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
const long double PI = acos(-1.0L);
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
//const int mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
VL dx={1,0,-1,0};
VL dy={0,1,0,-1};
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
const int N=500000;
vector<vector<PLL>> adj;
VL visit2;
map<ll,ll> gg;
bool dfs(ll v,ll p)
{
    gg[v]=1;
    visit2[v]=1;
    bool cyc=false;
    for(auto to:adj[v])
    {
        if(visit2[to.F]==1)
        {
            if(to.S!=p)
            {
                cyc=true;
            }
        }
        else
        {
            cyc|=dfs(to.F,to.S);
        }
    }
    return cyc;
}
void solve()
{
    ll n;
    cin>>n;
    vector<PLL> arr;
    map<ll,ll> mp,visited;
    map<PLL,VL> store;
    VL pres(N,0);
    visit2.assign(N,0);
    adj.assign(N,vector<PLL>());
    fr(i,0,n)
    {
        ll a,b;
        cin>>a>>b;
        pres[a]=1,pres[b]=1;
        if(a>b)
        {
            swap(a,b);
        }
        if(a==b)
        {
            mp[a]=1;
            visited[i]=1;
        }
        arr.pb({a,i});
        arr.pb({b,i});
        store[{a,b}].pb(i);
    }
    sort(ALL(arr));
    for(auto i:store)
    {
        if(SZ(i.S)>1)
        {
            PLL tmp=i.F;
            mp[tmp.F]=1;
            mp[tmp.S]=1;
            VL fk=i.S;
            visited[fk[0]]=1;
            visited[fk[1]]=1;
        }
        PLL tmp=i.F;
        VL fk=i.S;
        for(auto pp:fk)
        {
            adj[tmp.F].pb({tmp.S,pp});
            adj[tmp.S].pb({tmp.F,pp});
        }
    }
    //cout<<SZ(mp)<<endl;
    mp.clear();
    ll ans=0;
    fr(i,0,N)
    {
        if(pres[i]==1&&visit2[i]==0)
        {
            gg.clear();
            if(dfs(i,-1))
            {
                ans+=SZ(gg);
            }
            else
            {
                ans+=SZ(gg)-1;
            }
        }
    }
    cout<<ans<<endl;
    return; 
}
int main()
{
    IOS;
    ll t=1,pp;
    //cin>>t;
    pp=t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<": ";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * BE CAREFUL REGARDING THE DEFAULT VALUES IN segement trees etc
        * BE very careful in int vs long long vs unsigned long long 
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithmQ
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<string> s(n);
    ll odd = 0, even = 0;
    rep(i,n){
        string s;
        cin>>s;
        int sum=0;
        rep(j,m)sum+=s[j]-'0';
        if(sum%2)++odd;
        else ++even;
    }
    cout<<odd*even<<endl;
    return 0;
}