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

const int N = 20;

mt19937 mt;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    mt.seed(time(nullptr));
    int n, m;
    cin >> n >> m;
    vector<string> v(m);
    for (auto& i : v) {
        cin >> i;
    }
    //sort(v.begin(), v.end(), [](string a, string b){return a.size() < b.size();});
    shuffle(v.begin(), v.end(), mt);
    char a[N][N];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            a[i][j] = '.';
        }
    }
    int i = 0, j = 0;
    for (auto s : v) {
        if (j + s.size() >= n) {
            j = 0;
            ++i;
        }
        if (i >= n) {
            break;
        }
        for (int k = 0; k < s.size(); ++k, ++j) {
            a[i][j] = s[k];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cout << a[i][j];
        }
        cout << '\n';
    }
	return 0;
}

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

constexpr char LF = '\n';

template <typename T = int>
constexpr T INF()
{
    return numeric_limits<T>::max();
}

template <typename InputIterator>
void print(InputIterator first, InputIterator last)
{
    if (first != last) {
        cout << *first;
        for (auto p = next(first); p != last; p = next(p)) {
            cout << ' ' << *p;
        }
    }
    cout << LF;
}

void trace() { cout << LF; }

template <typename Head, typename... Tail>
void trace(Head head, Tail... tail)
{
    cout << head << ' ';
    trace(tail...);
}

class Problem {
    static constexpr size_t ML = 12;
    size_t N_, M_;
    vector<string> s_;
    vector<vector<pair<string, bool>>> v_;

private:
    void fill(string &t)
    {
        for (size_t j = ML; j > 1; --j) {
            auto p = v_.at(j).begin();
            while (p != v_.at(j).end() && N_ - t.size() > +j) {
                if (p->second) {
                    t += p->first;
                    p->second = false;
                }
                ++p;
            }
        }
        if (t.size() < N_) t += string(N_ - t.size(), '.');
    }

public:
    Problem()
    {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);

        cin >> N_ >> M_;
        s_.assign(M_, string());
        for (auto &&si : s_) cin >> si;
    }

    void solve()
    {
        v_.assign(ML + 1, vector<pair<string, bool>>());
        for (auto si : s_) {
            v_.at(si.size()).emplace_back(si, true);
        }
        vector<string> ans(N_);
        for (auto ans_it = ans.begin(); ans_it != ans.end(); ++ans_it) {
            fill(*ans_it);
        }
        string t;
        fill(t);
        for (size_t i = 0; i < N_; ++i) {
            ans.at(i).at(N_ - 1) = t.at(i);
        }
        for (auto r : ans) cout << r << LF;
    }
};

int main()
{
    Problem problem;
    problem.solve();
}
