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

#define f first
#define s second
#define pb push_back
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define db(x) cout << '>' << #x << ':' << x << endl;
#define sz(x) ((int)(x).size())
#define newl cout << "\n"

#define ll long long int
#define vi vector<int>
#define vll vector<long long>
#define vvll vector<vll>
#define pll pair<long long, long long>

#define fast_io()                                                              \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

ll tc, n, m, k;


int main() {
  fast_io();
#ifndef ONLINE_JUDGE
  freopen("../input.txt", "r", stdin);
  freopen("../output.txt", "w", stdout);
#endif

  cin>>n>>k;
  vvll dist(n, vll(n, 0));
  rep(i, 0, n) {
    rep(j, 0, n) cin>>dist[i][j];
  }

  vll vis(n, 0);

  ll ans = 0;
  function<void(int, int, int)> dfs = [&](int u, int time, int depth) {
    if(vis[u] && u == 0 && time == k && depth == n) {
      ans++;
      return;
    }

    if(vis[u]) return;
    vis[u] = 1;
    rep(v, 0, n) {
      if(v != u ) {
        if(v == 0 && depth == n-1 && vis[v]) {
          dfs(v, time + dist[u][v], depth+1);
        } else if(vis[v] == 0) {
          dfs(v, time + dist[u][v], depth+1);
        }
      }
    }
    vis[u] = 0;

  };

  dfs(0, 0, 0);

  cout<<ans;
  return 0;
}

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

int solve() {
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    if(r1 == r2 && c1 == c2) return 0;
    if(abs(r1-r2) + abs(c1-c2) <= 3) return 1;
    if(abs(r1-r2) == abs(c1-c2)) return 1;
    if(abs(r1+c1) % 2 == abs(r2+c2) % 2) return 2;
    ll dr = abs(r1-r2);
    if(abs((c1+dr) - c2) <= 3) return 2;
    if(abs((c1-dr) - c2) <= 3) return 2;
    return 3;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cout << solve() << endl;
}