#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define FAST_IO() \
{\
ios::sync_with_stdio(false);\
cin.tie(NULL); \
cout.tie(NULL); \
}\
using namespace std;
vector<string> ans(20), s(20);
vector<bool> vis(20);
int l, n;
void DFS(int cnt = 0)
{
if (cnt == l)
{
bool flag = true;
for (int i = 0; i < l; i++)
{
for (int j = i + 1; j < l; j++)
{
if (flag)
flag = (ans[i][j] == ans[j][i]);
}
}
if (flag)
{
for (int i = 0; i < l; i++)
{
for (int j = 0; j < l; j++)
cout << ans[i][j];
cout << "\n";
}
exit(0);
}
return;
}
for (int i = 0; i < n; i++)
{
// 백트래킹
if (!vis[i])
{
vis[i] = true;
ans[cnt] = s[i];
DFS(cnt + 1);
vis[i] = false;
}
}
}
int main()
{
FAST_IO();
cin >> l >> n;
for (int i = 0; i < n; i++)
cin >> s[i];
sort(s.begin(), s.begin() + n);
DFS();
cout << "NONE";
return 0;
}