#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
struct Edge {
  int from, to, rev, cap, flow, cost;
  Edge(int from, int to, int rev, int cap, int flow, int cost)
      : from(from), to(to), rev(rev), cap(cap), flow(flow), cost(cost) {}
};
vector<vector<Edge> > graph;
void addEdge(int from, int to, int cap, int cost) {
  graph[from].push_back(Edge(from, to, (int)graph[to].size(), cap, 0, cost));
  graph[to].push_back(Edge(to, from, (int)graph[from].size() - 1, 0, 0, -cost));
}
int N, K;
const int MAXN = 100 + 1;
int dist[MAXN];
int state[MAXN];
Edge* PIZDA[MAXN];
int calcMinCostMaxFlow() {
  int totalFlow = 0;
  for (;;) {
    for (int i = 0; i < N; ++i) {
      dist[i] = INF;
      state[i] = 2;
      PIZDA[i] = nullptr;
    }
    deque<int> deq;
    deq.push_back(0);
    dist[0] = 0;
    while (!deq.empty()) {
      int v = deq.front();
      deq.pop_front();
      state[v] = 2;
      for (auto& e : graph[v])
        if (e.cap > e.flow && dist[e.to] > dist[e.from] + e.cost) {
          dist[e.to] = dist[e.from] + e.cost;
          PIZDA[e.to] = &e;
          if (state[e.to] == 0) {
            deq.push_front(e.to);
          }
          if (state[e.to] == 2) {
            deq.push_back(e.to);
          }
          state[e.to] = 1;
        }
    }
    if (PIZDA[N - 1] == nullptr) {
      break;
    }
    int addFlow = INF;
    for (int v = N - 1; v != 0; v = PIZDA[v]->from) {
      addFlow = min(addFlow, PIZDA[v]->cap - PIZDA[v]->flow);
    }
    if (dist[N - 1] > 0) {
      addFlow = min(addFlow, K / dist[N - 1]);
    }
    if (addFlow == 0) {
      break;
    }
    totalFlow += addFlow;
    long long addCost = 0;
    for (int v = N - 1; v != 0; v = PIZDA[v]->from) {
      PIZDA[v]->flow += addFlow;
      graph[v][PIZDA[v]->rev].flow -= addFlow;
      addCost += 1LL * addFlow * PIZDA[v]->cost;
    }
    K -= addCost;
  }
  return totalFlow;
}
int main() {
  scanf("%d%d", &N, &K);
  graph.resize(N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j) {
      int cap;
      scanf("%d", &cap);
      if (cap > 0) {
        addEdge(i, j, cap, 0);
        addEdge(i, j, INF, 1);
      }
    }
  printf("%d\n", calcMinCostMaxFlow());
  return 0;
}
