#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10010;
const int MAXM = 100010;
const int INF = 0x3f3f3f3f;
struct Edge {
  int to, next, cap, flow, cost;
} edge[MAXM];
struct pp {
  int u, v, c, w;
} in[MAXN];
int head[MAXN], tol;
int pre[MAXN], dis[MAXN];
bool vis[MAXN];
int N = MAXN - 2;
int k, n;
void init() {
  tol = 0;
  memset(head, -1, sizeof(head));
}
void addv(int u, int v, int cap, int cost) {
  edge[tol].to = v;
  edge[tol].cap = cap;
  edge[tol].cost = cost;
  edge[tol].flow = 0;
  edge[tol].next = head[u];
  head[u] = tol++;
  edge[tol].to = u;
  edge[tol].cap = 0;
  edge[tol].cost = -cost;
  edge[tol].flow = 0;
  edge[tol].next = head[v];
  head[v] = tol++;
}
bool spfa(int s, int t) {
  queue<int> q;
  memset(dis, INF, sizeof(dis));
  memset(vis, 0, sizeof(vis)), memset(pre, -1, sizeof(pre));
  dis[s] = 0;
  vis[s] = true;
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = false;
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].to;
      if (edge[i].cap > edge[i].flow && dis[v] > dis[u] + edge[i].cost) {
        dis[v] = dis[u] + edge[i].cost;
        pre[v] = i;
        if (!vis[v]) {
          vis[v] = true;
          q.push(v);
        }
      }
    }
  }
  if (pre[t] == -1)
    return false;
  else
    return true;
}
int minCostMaxflow(int s, int t, int &cost) {
  int flow = 0;
  cost = 0;
  int tep;
  while (spfa(s, t)) {
    int Min = INF;
    tep = 0;
    for (int i = pre[t]; i != -1; i = pre[edge[i ^ 1].to]) {
      if (Min > edge[i].cap - edge[i].flow) Min = edge[i].cap - edge[i].flow;
    }
    for (int i = pre[t]; i != -1; i = pre[edge[i ^ 1].to]) {
      edge[i].flow += Min;
      edge[i ^ 1].flow -= Min;
      tep += edge[i].cost * Min;
    }
    if (cost + tep <= k) {
      cost += tep;
      flow += Min;
    } else {
      flow += (k - cost) / dis[n];
      return flow;
    }
  }
  return flow;
}
int main() {
  cin >> n >> k;
  init();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int x;
      cin >> x;
      if (x) {
        addv(i, j, x, 0);
        addv(i, j, k, 1);
      }
    }
  }
  int cost = 0;
  printf("%d\n", minCostMaxflow(1, n, cost));
}
