#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n, k;
    cin >> n >> k;
    vector<vector<int>> t(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> t[i][j];
        }
    }

    int ans = 0;

    // 全探索

    vector<int> order(n - 1);
    iota(order.begin(), order.end(), 1);
    do {
        int time = t[0][order.front()];
        for (int i = 1; i < n - 1; i++) {
            time += t[order[i]][order[i - 1]];
        }
        time += t[order.back()][0];

        if (time == k) ans++;

    } while (next_permutation(order.begin(), order.end()));

    cout << ans << "\n";
}

#include "bits/stdc++.h"
#pragma GCC optimize "trapv"

#define int long long int
#define For(i,a,b) for(int  i=a;i<b;i++)

#define pb push_back
#define endl "\n"

#define F first
#define S second

#define drink_boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v) v.begin(),v.end()

#define TEST_CASE int  t;cin>>t;while(t--)
#define debug(...) cout<<#__VA_ARGS__<<" = "; print(__VA_ARGS__);

using namespace std;
const int MOD = 1e9 + 7;

void print()  {    cout<<endl;  }
void printArray()  {    return;  }
void read() { return; }

template<typename T , typename... Args>  void print(T a , Args... arg)    {    cout << a << " " ;    print(arg...);    }

template<typename T , typename... Args> void read(T &a , Args&... arg) {   cin >> a;   read(arg...);   }

template<typename T,typename... Args> void read(vector<T>&v , Args&... arg) {  for(auto &i : v)  cin>>i;  read(arg...);  }

template<typename T,typename... Args> void printArray(vector<T>&v, Args&... arg) {   for(auto i : v)     cout<<i<<" ";   cout<<endl;  printArray(arg...);    }

int power(int a,int b) { int  res=1; while(b) { if(b&1LL) res=res*a; b>>=1LL; a=a*a; } return res; }
    
int modPower(int a,int b) { int res=1; while(b) { if(b&1L) res=(res%MOD*a%MOD)%MOD; b>>=1; a=(a%MOD*a%MOD)%MOD; } return res; }

int gcdExtended(int a,int b,int *x,int *y){ if(a==0) { *x=0,*y=1; return b; } int x1,y1; int gcd=gcdExtended(b%a,a,&x1,&y1); *x=y1-(b/a)*x1; *y = x1; return gcd; }

int modInverse(int b,int m) {int x,y; int g=gcdExtended(b,m,&x,&y); if (g != 1) return -1; return (x%m + m) % m; }

int modDivide(int a,int b,int m=MOD) { a=a%m; int inv=modInverse(b,m); if(inv==-1) return -1; else return (inv*a)%m; }

int Time[11][11];

int timeTaken(vector<int>&v)
{
    int t = 0 , n = v.size(),last = 1;
    For(i,0,n)
    {
        t = t + Time[last][v[i]];
        last = v[i];
    }
    t += Time[last][1];
    return t;
}

void runCase_()
{
    int n,k;
    read(n,k);
    For(i,1,n+1)
        For(j,1,n+1)
            read(Time[i][j]);
    vector<int>v;
    int ans = 0;
    For(i,2,n+1) v.pb(i);
    do 
    {
        int t = timeTaken(v);
        // printArray(v);
        // debug(t);
        if(t == k) ++ans;
    }
    while(next_permutation(all(v)));
    print(ans);
}

signed main()
{
    drink_boost;
    // TEST_CASE
    runCase_();
    return 0;
}

/** TEST CASES HERE **/
/*

*/

