#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ull> ull1d;
typedef vector<ull1d> ull2d;
typedef vector<ull2d> ull3d;
#define loop(i,n) for(ull i=0;i<n;i++)
#define rloop(i,n) for(ll i=n-1;i>=0;i--)
#define all(vec) vec.begin(),vec.end()
template<class T> inline bool chmin(T& a,T b){ if(a>b){ a=b; return true;} return false; }
template<class T> inline bool chmax(T& a,T b){ if(a>b){ a=b; return true;} return false; }

int main(){ cout << fixed << setprecision(15);
  int n,m;
  cin >> n >> m;
  vector<string> a,b(m);
  loop(i,m){ cin >> b[i]; }
  sort(all(b),[](string &x, string &y){ return x.size() > y.size(); });
  loop(i,b.size()) for(int j=i+1;j<b.size();j++){
    if(b[i].find(b[j]) != string::npos){
      b.erase(b.begin()+j);
    }
  }
  string prev = "";
  loop(i,b.size()){
    if(prev.size() + b[i].size() > n){
      int l = n-prev.size();
      auto itr = find_if(all(b),[l](string x){ return x.size() == l; });
      if(itr == b.end()){
        loop(j,l){ prev += "."; }
      }
      else{
        prev += *itr;
        b.erase(itr);
      }
      a.push_back(prev);
      prev = "";
    }
    prev += b[i];
  }
  loop(i,n){
    cout << a[i] << endl;
  }
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
int edge[10][10], mark[10];
int n, k, v = 1, ans = 0;

void dfs(int cur, int dst) {
    if(dst > k) return;
    if(v == n) {
        if(dst + edge[0][cur] == k) ans ++;
        return;
    }    
    else {
        for(int i = 0; i <= n; i++) {
            if(mark[i] == 0) {
                mark[i] = 1;
				v ++;
				//cout<<cur<<' '<<i<<' '<<dst<<endl;
                dfs(i, dst + edge[cur][i]);
                mark[i] = 0;
				v --;
            }
        }
        return;
    }
}

int main() {
	cin>>n>>k;
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++) {
			cin>>edge[i][j];
		}
	}
	memset(mark, 0, sizeof(mark));
	mark[0] = 1;
	dfs(0, 0);
	cout<<ans;

	return 0;
}