#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;

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

    vector<int> route;
    for (int i = 2; i <= n; i++) {
        route.push_back(i);
    }

    int res = 0;
    do {
        int sum = 0;
        int prev_city = 1;
        for (auto next_city : route) {
            sum += t[prev_city - 1][next_city - 1];
            prev_city = next_city;
        }
        sum += t[route.back() - 1][0];
        if (sum == k) res++;
    } while (next_permutation(route.begin(), route.end()));

    cout << res << endl;

    return 0;
}
#include <bits/stdc++.h>
// #include <atcoder/modint>
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define INF 2000000000000000000
#define ll long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<bool>> connection(N, vector<bool>(N, false));
  map<pll, ll> mp;
  vector<pll> ans(M, {-1, -1});
  vector<pll> data(M);
  for (ll i = 0; i < M; ++i) {
    ll a, b;
    cin >> a >> b;
    a -= 1, b -= 1;
    data.at(i) = {a, b};
    mp[{a, b}] = i;
    mp[{b, a}] = i;
    connection.at(a).at(b) = true;
    connection.at(b).at(a) = true;
  }
  vector<ll> C(N);
  for (ll i = 0; i < N; ++i) {
    cin >> C.at(i);
  }
  for (ll m = 1; m <= N; ++m) {
    for (ll i = 0; i < N; ++i) {
      if (C.at(i) == m) {
        stack<ll> st;
        st.push(i);
        while (!st.empty()) {
          ll now = st.top();
          bool found = false;
          for (ll j = 0; j < N; ++j) {
            if (connection.at(now).at(j) && C.at(j) == m && ans.at(mp[{now, j}]) == (pll){-1, -1}) {
              found = true;
              ans.at(mp[{now, j}]) = {now, j};
              if (j != i) {
                st.push(j);
              }
              break;
            }
          }
          if (!found) {
            st.pop();
          }
        }
      }
    }
  }
  for (ll i = 0; i < M; ++i) {
    ll a = data.at(i).first, b = data.at(i).second;
    if (C.at(a) > C.at(b)) {
      ans.at(i) = {a, b};
    }
    if (C.at(a) < C.at(b)) {
      ans.at(i) = {b, a};
    }
  }
  for (ll i = 0; i < M; ++i) {
    if (ans.at(i) == data.at(i)) {
      cout << "->" << "\n";
    }
    else {
      cout << "<-" << "\n";
    }
  }
}
