#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#if 0 //B
#include <iomanip>
#endif
using namespace std;

long long int T[8][8];
int N, K;

int root[9] = { -1,-1,-1,-1,-1,-1,-1,-1,-1 }; // 通る経路。

bool isVisited[8] = { false,false, false, false, false, false, false, false };

int counter = 0;

vector<int> get_unvisited_city(){
    vector<int> vec_city;
    for (int i = 0; i < N; i++) {
        if (isVisited[i] == false) {
            vec_city.push_back(i);
        }
    }
    return vec_city;
}



int number_unvisited() {
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (isVisited[i] != true) cnt++;
    }
    return cnt;
}

// 未訪問の都市IDの中から最も若いIDの都市IDを返す関数。すべて訪問済みなら0を返す
int getUnvisitedCityID() {
    for (int i = 0; i < N; i++) {
        if (isVisited[i] == false) {
            return i;
        }
    }
    return 0;
}

// 階乗をおこなう関数
int kaijou(int x) {
    int ret = 1;
    for (int i = 1; i <= x; i++) {
        ret *= i;
    }
    return ret;
}

void calcTime() {
    long long time = 0;
    for (int i = 0; i < N; i++) {
        int from = root[i];
        int to = root[i + 1];
        time += T[from][to];
    }
    if (time == K) {
        counter++;
    }
}

// n番目に訪問する都市を決める関数
int DecideCityID(int n) {
    if (n == N) {
        // ルートが決まったので時間の計算

        calcTime();
        return 0;
    }
    vector<int> vec_city = get_unvisited_city();
    for (auto it = vec_city.begin(); it != vec_city.end(); it++) {
        isVisited[*it] = true;
        root[n] = *it;

        DecideCityID(n + 1);

        isVisited[*it] = false;
        root[n] = -1;
    }
    return 0;
}



int main()
{

    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> T[i][j];
        }
    }

    int pattern = kaijou(N-1);

    bool root_decided = false;

    root[0] = root[N] = 0;

    int from, to;
    from = 0;
    isVisited[from] = true;
    DecideCityID(1);

    to = getUnvisitedCityID();
    
    cout << counter;
    return 0;

}

// #pragma GCC optimise ("O1")
#include<bits/stdc++.h>
using namespace std;
#define ll           int
#define rep(i,j,n)   for(ll i=j;i<n;i++)
#define scn(a)       scanf("%d",&a)
#define scns(a,b)    scanf("%d %d",&a,&b)
#define print(a)     printf("%0.10lf",a)
#define vec          vector<ll>
#define pb           push_back    
#define pairs        pair<ll,ll>
#define f            first
#define s            second
#define all(v)       v.begin(),v.end()
#define srt(v)       sort(v.begin(),v.end())
#define read(a)       for(auto &it:a) cin>>it;
#define write(a)       for(auto it:a) cout<<it<<" ";
#define mem(a,b)     memset(a,b,sizeof(a))
#define nl           printf("\n")
#define inf          1e9
#define zer          INT_MIN
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int N=2e3+5;


int main()
{
  int t=1; 
  // cin>>t;
  while(t--)
  {
    int n,k; scns(n,k);
    int cost[n+5][n+5];

    rep(i,1,n+1)
    rep(j,1,n+1)
    scn(cost[i][j]);

    vec v;
    int cnt=0;
    rep(i,2,n+1)
    v.pb(i);

    do
    {
      int amt=0;
      amt+=cost[1][v[0]];

      // for(auto it:v)
      // cout<<it<<" ";
      // cout<<endl;

      rep(i,1,v.size())
      amt+=(cost[v[i-1]][v[i]]);
      amt+=cost[v[v.size() - 1]][1];

      // cout<<amt<<" ";

      if(amt==k)
      cnt++;
    } while(next_permutation(all(v)));

    cout<<cnt;
  }
}
