#include <bits/stdc++.h>

using namespace std;

struct compare {
    inline bool operator()(const std::string& first,
            const std::string& second) const
    {
        return first.size() < second.size();
    }
};

int main() {
  int n, m;
  cin>>n>>m;
  string ins[m];
  for (int i=0; i<m; i++) cin>>ins[i];

  vector<string> s;
  for (int i=0; i<m; i++) {
    bool contains = false;
    for (int j=0; j<m; j++) {
      if (i == j) {
        continue;
      }
      if (ins[j].find(ins[i]) != -1) {
        contains = true;
        break;
      }
    }
    if (!contains) {
      s.push_back(ins[i]);
    }
  }
  compare c;
  sort(s.begin(), s.end(), c);
  reverse(s.begin(), s.end());

  vector<string> result[20];
  vector<string> suffix[20];
  int len[20];
  for (int i=0; i<20; i++) len[i] = 0;
  int i = 0;
  for (string si: s) {
    for (int i=0; i<20; i++) {
      bool match_suffix = false;
      for (string i_suffix : suffix[i]) {
        if (len[i] + si.length() - i_suffix.length() > 20) {
          continue;
        }
        if (i_suffix == si.substr(0, i_suffix.length())) {
          match_suffix = true;
          result[i].push_back(si.substr(i_suffix.length()));
          len[i] += si.length() - i_suffix.length();
          break;
        }
      }
      if (!match_suffix) {
        if (len[i] + si.length() > 20) {
          continue;
        }
        result[i].push_back(si);
        len[i] += si.length();
      }
      suffix[i].clear();
      for (int j=0; j<si.length()-1; j++) {
        suffix[i].push_back(si.substr(j+1));
      }

      break;
    }
  }
  for (int i=0; i<20; i++) {
    for (string r : result[i]) {
      cout<<r;
    }
    for (int j=len[i]; j<20; j++) {
      cout<<"A";
    }
    cout<<endl;
  }
}
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w,count=0;
  cin>>h>>w;
  vector<string>s(h);
  for(int i=0;i<h;i++)cin>>s.at(i);
  for(int i=0;i<h;i++){
    for(int j=0;j<w-1;j++){
      if(s.at(i).at(j)=='.'&&s.at(i).at(j+1)=='.'){
        count++;
      }
    }
  }
  for(int i=0;i<h-1;i++){
    for(int j=0;j<w;j++){
      if(s.at(i).at(j)=='.'&&s.at(i+1).at(j)=='.'){
        count++;
      }
    } 
  }
  cout<<count;
}
    

