#include <bits/stdc++.h>
using namespace std;
struct node {
  int from;
  int to;
  int w;
  int next;
  int num;
  int f;
} e[1515151];
int head[1212];
int pre[1212];
int path[1212];
int dis[1212];
int vis[1212];
int n, m, cont, ss, tt, k;
void add(int from, int to, int f, int w) {
  e[cont].num = cont;
  e[cont].f = f;
  e[cont].w = w;
  e[cont].to = to;
  e[cont].next = head[from];
  head[from] = cont++;
}
int SPFA() {
  queue<int> s;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) dis[i] = 0x3f3f3f3f;
  dis[ss] = 0;
  s.push(ss);
  while (!s.empty()) {
    int u = s.front();
    s.pop();
    vis[u] = 0;
    for (int i = head[u]; i != -1; i = e[i].next) {
      int v = e[i].to;
      int w = e[i].w;
      int f = e[i].f;
      if (f && dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        pre[v] = u;
        path[v] = e[i].num;
        if (vis[v] == 0) {
          vis[v] = 1;
          s.push(v);
        }
      }
    }
  }
  if (dis[tt] == 0x3f3f3f3f)
    return 0;
  else
    return 1;
}
void MCMF() {
  int maxflow = 0;
  int ans = 0;
  while (SPFA() == 1) {
    int minn = 0x3f3f3f3f;
    for (int i = tt; i != ss; i = pre[i]) {
      minn = min(minn, e[path[i]].f);
    }
    for (int i = tt; i != ss; i = pre[i]) {
      e[path[i]].f -= minn;
      e[path[i] ^ 1].f += minn;
    }
    if (k == 0) {
      maxflow += minn;
      continue;
    }
    if (ans + minn * dis[tt] > k) {
      maxflow += (k - ans) / dis[tt];
      break;
    }
    ans += minn * dis[tt];
    maxflow += minn;
    if (ans == k) break;
  }
  printf("%d\n", maxflow);
}
int main() {
  while (~scanf("%d%d", &n, &k)) {
    cont = 0;
    ss = 1;
    tt = n;
    memset(head, -1, sizeof(head));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        int tmp;
        scanf("%d", &tmp);
        if (tmp == 0)
          continue;
        else {
          add(i, j, tmp, 0);
          add(j, i, 0, 0);
          add(i, j, k, 1);
          add(j, i, 0, -1);
        }
      }
    }
    MCMF();
  }
}
