#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:33554432")
int N, K, ans;
int w[51][51], o[51][51];
int dist[51], from[51];
bool vis[51];
vector<int> path;
priority_queue<pair<int, int> > que;
bool dfs(int n) {
  int i;
  path.push_back(n);
  vis[n] = 1;
  if (n == N) return 1;
  for (i = 1; i <= N; i++)
    if (!vis[i] && w[n][i] && dfs(i)) return 1;
  path.pop_back();
  return 0;
}
int main() {
  int i, j;
  scanf("%d%d", &N, &K);
  for (i = 1; i <= N; i++)
    for (j = 1; j <= N; j++) {
      scanf("%d", w[i] + j);
      o[i][j] = w[i][j];
    }
  while (dfs(1)) {
    int flow = 2e9;
    for (i = 1; i < ((int)(path).size()); i++)
      flow = min(flow, w[path[i - 1]][path[i]]);
    for (i = 1; i < ((int)(path).size()); i++)
      w[path[i - 1]][path[i]] -= flow, w[path[i]][path[i - 1]] += flow;
    memset(vis, 0, sizeof(vis));
    path.clear();
    ans += flow;
  }
  while (K--) {
    while (!que.empty()) que.pop();
    for (i = 1; i <= N; i++) dist[i] = 1e9;
    dist[1] = 0;
    que.push(make_pair(0, 1));
    while (!que.empty()) {
      int d = -que.top().first;
      int q = que.top().second;
      que.pop();
      if (dist[q] != d) continue;
      for (i = 1; i <= N; i++)
        if (o[q][i]) {
          if (dist[i] > dist[q] + !w[q][i])
            dist[i] = dist[q] + !w[q][i], que.push(make_pair(-dist[i], i)),
            from[i] = q;
        }
    }
    if (dist[N] == 1e9) break;
    for (i = N; i > 1;) {
      j = from[i];
      if (!w[j][i]) {
        w[j][i]++;
        break;
      }
      i = j;
    }
    path.clear();
    memset(vis, 0, sizeof(vis));
    if (dfs(1)) {
      for (i = 1; i < ((int)(path).size()); i++)
        w[path[i - 1]][path[i]]--, w[path[i]][path[i - 1]]++;
      ans++;
    }
  }
  printf("%d\n", ans);
}
