#include<bits/stdc++.h>
#define REP(i,b,e) for(int i=b;i<e;i++)

int main(){
	int n, m;
	std::cin >> n >> m;
	std::string ss[m];
	REP(i, 0, m) std::cin >> ss[i];

	std::string ans[n];
	bool used[m] = {};

	REP(si, 0, m){

		int minrow = 0, crost = 50, min_add_len = ss[si].size();
		REP(i, 0, n){
			REP(j, 0, ans[i].size()){
				std::string s1 = ans[i].substr(j);
				std::string s2 = ss[si].substr(0, ans[i].size()-j);
				if(s1 != s2) continue;

				int pushlen = ss[si].size() - ans[i].size() + j;
				if(ans[i].size() + pushlen < n && min_add_len > pushlen){
					min_add_len = pushlen;
					minrow = i;
					crost = j;
				}
			}
		}

		crost = std::min<int>(crost, ans[minrow].size());
		std::string pushs = ss[si].substr(ans[minrow].size() - crost);
		while(minrow < n && ans[minrow].size() + pushs.size() > n) minrow++;
		if(minrow == n) continue;
		ans[minrow] += pushs;
		used[si] = true;

		//for(auto &s: ans) std::cout << s << '\n'; puts("");
	}

	


	REP(si, 0, m) if(!used[si]) {

		std::sort(ans, ans+n, [](std::string x, std::string y){
			return x.size() > y.size();
		});

		REP(j, 0, n){
			int ok_cnt = 0;
			REP(i, 0, n){
				if(ans[i].size() <= j) ok_cnt++;
			}
			if(ok_cnt < ss[si].size()) continue;

			int idx = 0;
			REP(i, 0, n){
				if(idx >= ss[si].size()) break;
				if(ans[i].size() <= j){
					ans[i] += std::string(j - ans[i].size(), '.');
					ans[i] += ss[si][idx];
					idx++;
				}
			}
			used[si] = true;
			break;
		}
	}

	for(auto &s: ans){
		if(s.size() < n){
			 s += std::string(n-s.size(), '.');
		}
	}

	for(auto &s: ans){
		std::cout << s << '\n';
	}
	return 0;
}



#include<bits/stdc++.h>
using namespace std;

int main() {
    mt19937 rng(48);
    cout.tie(nullptr)->sync_with_stdio(false);
    int N, M; cin >> N >> M;
    
    array<array<bool, 20>, 20> graph{};
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b;
        --a, --b;
        graph[a][b] = graph[b][a] = true;
    }

    int mi = N;
    vector<int> S(N), cc(N);
    iota(S.begin(), S.end(), 0);

    while (clock() <= 1.9 * CLOCKS_PER_SEC) {
        shuffle(S.begin(), S.end(), rng);
        int color = 1;
        for (int i = 1; i < N; ++i) {
            int Q = 0;
            for (int j = 0; j < i; ++j) {
                if (!graph[S[j]][S[i]]) Q |= (1 << cc[j]);
            }
            Q ^= (1 << color) - 1;
            if (Q == 0) {
                cc[i] = color++;
            } else {
                while (true) {
                    cc[i] = uniform_int_distribution<int>(0, color + 1)(rng);
                    if (Q & (1 << cc[i])) break;
                }
            }
        }
        mi = min(mi, color);
    }

    cout << mi << '\n';
}
