#include <algorithm>
#include <bitset>
//#include <cmath>
//#include <complex>
#include <cctype>
#include <cstdio>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
#include <unordered_set>
#include <unordered_map>

using namespace std;

int64_t INF = LLONG_MAX;


int check(vector<vector<char>> &grid, int i, int j, string &current, int mode){
    int cost = 0;
    
    if(mode == 0){
        //横の探索
        for(int k = 0; k < current.size(); k++){
            if(grid.at(i).at((j+k)%20) == '.'){
                cost++;
            }else if(grid.at(i).at((j+k)%20) == current.at(k)){
                continue;
            }else{
                return -1;
            }
        }
    }else{
        //縦の探索
        for(int k = 0; k < current.size(); k++){
            if(grid.at((i+k)%20).at(j) == '.'){
                cost++;
            }else if(grid.at((i+k)%20).at(j) == current.at(k)){
                continue;
            }else{
                return -1;
            }
        }
    }
    
    return cost;
}

void update(vector<vector<char>> &grid, int i, int j, string &current, int mode){
    if(mode == 0){
        //横の探索
        for(int k = 0; k < current.size(); k++){
            if(grid.at(i).at((j+k)%20) == '.'){
                grid.at(i).at((j+k)%20) = current.at(k);
            }
        }
    }else{
        //縦の探索
        for(int k = 0; k < current.size(); k++){
            if(grid.at((i+k)%20).at(j) == '.'){
                grid.at((i+k)%20).at(j) = current.at(k);
            }
        }
    }
}


void run(vector<vector<char>> &grid, vector<string> &s){
    for(string current : s){
        int mini, minj, mode, cost;
        mini = minj = mode = -1;
        cost = 100;
        for(int i = 0; i < 20; i++){
            for(int j = 0; j < 20; j++){
                int tmpcost;
                tmpcost = check(grid, i, j, current, 0);
                if(tmpcost != -1){
                    if(cost > tmpcost){
                        mini = i;
                        minj = j;
                        mode = 0;
                        cost = tmpcost;
                    }
                }
                
                tmpcost = check(grid, i, j, current, 1);
                if(tmpcost != -1){
                    if(cost > tmpcost){
                        mini = i;
                        minj = j;
                        mode = 1;
                        cost = tmpcost;
                    }
                }
            }
        }
        
        if(cost == 100){
            continue;
        }
        
        update(grid, mini, minj, current, mode);
    }
}

void output(vector<vector<char>> &grid){
    for(int i = 0; i < 20; i++){
        for(int j = 0; j < 20; j++){
            cout << grid.at(i).at(j);
        }
        cout << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N, M;
    cin >> N >> M;
    
    vector<vector<char>> grid(N, vector<char>(N, '.'));
    
    
    vector<string> s(M);
    for(int i = 0; i < M; i++){
        cin >> s.at(i);
    }
    
    sort(s.begin(), s.end(), [](auto a, auto b){
        return a.size() > b.size();
    });
    
    
    run(grid, s);
    output(grid);
    
    return 0;
}

// #define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 5e6 + 10;
int fact[N], ifact[N], inv[N];

struct comb_init {
  comb_init() {
    inv[1] = 1;
    for (int i = 2; i < N; ++i) {
      inv[i] = (MOD - MOD / i) * (int64)inv[MOD % i] % MOD;
    }
    fact[0] = ifact[0] = 1;
    for (int i = 1; i < N; ++i) {
      fact[i] = (int64)fact[i - 1] * i % MOD;
      ifact[i] = (int64)ifact[i - 1] * inv[i] % MOD;
    }
  }
} comb_init_;

int64 comb(int n, int m) {
  if (n < m || m < 0) return 0;
  return (int64)fact[n] * ifact[m] % MOD * ifact[n - m] % MOD;
}

int main() {
  int n, m;
  cin >> n >> m;
  m += n;
  vector<int> a(n);
  int sum = n;
  for (int i = 0; i < n; ++i) cin >> a[i], sum += a[i];
  int ret = 1;
  trace(m, sum);
  for (int i = 0; i < sum; ++i) ret = 1LL * ret * (m - i) % MOD;
  ret = 1LL * ret * ifact[sum] % MOD;
  cout << ret << '\n';
  return 0;
}
