#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int ans = 0;
int n, k;
long t[8][8];

void saiki(int count, int go, long dist, int now) {
  if (count == n-1) {
    if (dist + t[now][0] == k) {
      ans++;
    }
  }
  else {
    for (int i = 1; i < n; i++) {
      if (((1 << i) & go) == 0) {
        saiki(count + 1, (go | (1 << i)), dist + t[now][i], i);
      }
    }
  }
}

int main() {
  int go = 0;

  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> t[i][j];
    }
  }
  saiki(0, 0, 0, 0);
  
  cout << ans;
}
#include<bits/stdc++.h>
using namespace std;

#define endl "\n"
#define int long long
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define trace(x) cerr<<#x<<" : "<<x<<endl;

int cnt = 0;
bool vis[2002];

void dfs(int idx, vector<int> v[])
{
    vis[idx] = true;
    for(auto it:v[idx])
    {
        if(!vis[it])
        {
            dfs(it, v);
            cnt++;
        }
    }
}

void solve()
{
    int n, m;
    cin >> n >> m;

    vector<int> v[n];

    for (int i = 0; i < m;i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        v[x].push_back(y);
    }

    int ans = 0;
    for (int i = 0; i < n;i++)
    {
        cnt = 0;
        memset(vis, false, sizeof(vis));
        dfs(i, v);
        ans += cnt;
    }
    cout << ans + n;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    for(int i=0;i<t;i++) solve();
    return 0;
}