#include <iostream>
using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    ll n_odd = 0;
    bool odd;
    cin >> n >> m;
    string s;
    for(int i = 0; i < n; i++) {
        cin >> s;
        odd = 0;
        for(char c : s) {
            if(c == '1') {
                odd = !odd;
            }
        }
        n_odd += odd;
    }
    cout << n_odd * (n - n_odd);
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
using ll=int64_t;
using ld=long double;
using ull=unsigned long long;
template <class T>
using grid=vector<vector<T>>;
#define ALL(x) x.begin(),x.end()
#define rep(iter,from,to) for(ll iter=from;iter<to;++iter)

const ll MOD = 1e9 + 7;
const ll INF = 1e17;
//#######################################################################
vector<vector<ll>> input(ll N, ll width) {
    string str;
    vector<vector<ll>> vec(N, vector<ll>(width));
    for (ll i = 0; i < N; ++i) {
        cin >> str;
        reverse(ALL(str));
        for (ll j = 0; j < width; ++j) {
            vec[i][j] = str.back();
            str.pop_back();
        }
    }
    return vec;
}
void op(vector<ll> vec) {
    ll size = (ll)vec.size();
    for (ll i = 0; i < size - 1; ++i) cout << vec[i] << " ";
    cout << vec.back() << endl;
}

void op(vector<vector<ll>> vec) {
    ll height = (ll)vec.size();
    ll width = (ll)vec[0].size();
    for (ll i = 0; i < height; ++i) {
        for (ll j = 0; j < width - 1; ++j) cout << vec[i][j] << " ";
        cout << vec[i].back() << endl;
    }
}
//########################################################################



int solve(){
    ll N,M;
    cin>>N>>M;
    vector<pair<ll,string>> dict;
    rep(i,0,M){
        string s;
        cin>>s;
        dict.emplace_back(s.size(),s);
    }
    grid<char> res(N,vector<char>(N,'.'));
    sort(ALL(dict));
    string use=dict.front().second;
    for(ll i=0;i<N;++i) {
        ll iter=0;
        ll start=0;
        while(true){
            rep(j,0,dict[0].first) {
                res[i][start+j]=dict[0].second[j];
            }
            start+=dict[0].first;
            if(start+dict[0].first>=N-1) break;
        }
    }
    rep(i,0,N) {
        rep(j,0,N) cout<<res[i][j];
        cout<<endl;
    }
    return 0;
}


int main(void){
    std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}
