#define ll long long
#define dd long double
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define tri tuple<ll ,ll ,ll>
#define tll tuple<ll ,ll , ll , ll> 
#define pll pair<ll ,ll> 
#include<bits/stdc++.h>
/*#include<iomanip>   
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<bitset>*/
dd pi = acos(-1) ;
ll z =  1000000007 ;
ll inf = 100000000000000000 ;
ll p1 = 37 ;
ll p2 = 53 ;
ll mod1 =  202976689 ;
ll mod2 =  203034253 ;
ll fact[1000005] ;
ll gdp(ll a , ll b){return (a - (a%b)) ;}
ll ld(ll a , ll b){if(a < 0) return -1*gdp(abs(a) , b) ; if(a%b == 0) return a ; return (a + (b - a%b)) ;} // least number >=a divisible by b
ll gd(ll a , ll b){if(a < 0) return(-1 * ld(abs(a) , b)) ;    return (a - (a%b)) ;} // greatest number <= a divisible by b
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll e_gcd(ll a , ll b , ll &x , ll &y){ if(b > a) return e_gcd(b , a , y , x) ; if(b == 0){x = 1 ; y = 0 ; return a ;}
ll x1 , y1 , g; g = e_gcd(b , a%b , x1 , y1) ; x = y1 ; y = (x1 - ((a/b) * y1)) ; return g ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
ll min(ll a , ll b){if(a < b) return a ; return b ;}
ll left(ll i){return ((2*i)+1) ;}
ll right(ll i){return ((2*i) + 2) ;}
ll ncr(ll n , ll r){if(n < r|| (n < 0) || (r < 0)) return 0 ; return ((((fact[n] * inverse(fact[r] , z)) % z) * inverse(fact[n-r] , z)) % z);}
void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;}
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
//__builtin_popcount(n) -> returns number of set bits in n
ll seed;
mt19937 rnd(seed=chrono::steady_clock::now().time_since_epoch().count()); // include bits


void solve()
{
    
    ll n , m ;
    cin >> n >> m ;
    string str ;
    ll even = 0 , odd = 0 ;
    fo(i , n)
    {
        cin >> str ;
        ll cnt = 0 ;
        fo(j , m)
            if(str[j] == '1')
                cnt++ ;
        if(cnt%2 == 0)
            even++ ;
        else
            odd++ ;
    }
    cout << even*odd << '\n' ;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    /*#ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("errorf.txt" , "w" , stderr) ;
    #endif*/
    
    ll c ;
    //cin >> c ;
    c = 1 ;

    
    for(ll x = 1 ; x <= c ; x++)
    {
       solve() ;
    }
    //cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
 
    return 0;
}
// Created by ...
#include <bits/stdc++.h>

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define sz(x) (int)(x).size()
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define per(i,a,b) for(ll i = a; i >= b; --i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) (a).begin(),(a).end()
#define EACH(x, a) for (auto& x:a)
#define se second
#define fi first
#define inf 0xffffffff
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
template<class T> T Min(T a,T b){if(a<b)return a; return b;}
template<class T> T Max(T a,T b){if(a>b)return a; return b;}
string x,mstr;
int m,n;

string Add(string s,string t)
{
	vll ans(Max(s.size(),t.size())+5,0);
	reverse(all(s)); reverse(all(t));
	rep(i,0,Max(s.size(),t.size())-1)
	{
		int x=0;
		if(i<s.size())x+=(s[i]-'0');
		if(i<t.size())x+=(t[i]-'0');
		ans[i]=x;
	}
	rep(i,0,ans.size()-2)
	{
		int x=ans[i]/10;
		ans[i+1]+=x;
		ans[i]%=10;
	}
	int val;
	reverse(all(ans));
	rep(i,0,ans.size()-1)if(ans[i]!=0){val=i;break;}
	string re="";
	rep(i,val,ans.size()-1)re+=(ans[i]+'0');
	return re;
}

string multiply(string s,int n){
	if(n==0 || s.empty())return "0";
	reverse(all(s));
	string ans;
	int carry=0;
	for(char c:s){
		int x=carry+(c-'0')*n;
		ans+=(x%10+'0');
		carry=x/10;
	}
	while(carry){
		ans+=(carry%10+'0');
		carry/=10;
	}
	reverse(all(ans));
	return ans;
}
bool check(int base){
	if(base==0)return true;
	string val;
	rep(i,0,n-1){
		val=Add(multiply(val,base),string(1,x[i]));
	}

	//cout<<val<<":"<<base<<endl;
	if(val.size()==mstr.size()){
		rep(i,0,sz(val)-1){
			if(val[i]!=mstr[i])
				return val[i]<mstr[i];
		}
		return true;
	}
	return val.size()<mstr.size();
}
int32_t main() {
    IOS;
    	cin>>x>>m;
    	n=sz(x);
    	if(n==1){
    		if(x[0]-'0'<=m)cout<<"1";
    		else cout<<"0";
    		return 0;
    	}
        int d=x[0]-'0';
        for(auto c:x){
        	int cc=c-'0';
        	d=Max(d,cc);
        }
        int temp=m;
        while(temp){
        	mstr+=(temp%10+'0');
        	temp/=10;
        }
        reverse(all(mstr));
        //cout<<mstr<<endl;
        int low=0,high=1e18,ans=low,mid;
       	while(low<=high){
        	mid=(low+high)>>1;
        	//cout<<mid<<endl;
        	if(check(mid)){
        		ans=mid;
        		low=mid+1;
        	}
        	else high=mid-1;
        }
        cout<<Max(0LL,ans-d);

        cout<<'\n';
    return 0;
}