#include <bits/stdc++.h>
using namespace std;
int n, k, m;
int a[105][105];
int ans;
set<pair<int, int> > bad;
bool check(int row, int col) {
  if (row < 0 || col < 0 || row + 1 >= n || col + 1 >= m) return true;
  int cnt = 0;
  for (int i = 0; i <= 1; i++)
    for (int j = 0; j <= 1; j++)
      if (a[row + i][col + j] == 0) cnt++;
  if (cnt & 1) return false;
  return true;
}
void find(int d) {
  if (bad.size() == 0) {
    ans = min(ans, d);
    return;
  }
  if (d >= k) return;
  if (bad.size() > 4 * (k - d)) return;
  pair<int, int> p = (*bad.begin());
  for (int i = 0; i <= 1; i++) {
    for (int j = 0; j <= 1; j++) {
      vector<pair<int, int> > added, deleted;
      a[p.first + i][p.second + j] ^= 1;
      for (int l = -1; l <= 0; l++)
        for (int m = -1; m <= 0; m++) {
          int A = p.first + i + l;
          int b = p.second + j + m;
          if (check(A, b) && bad.find(make_pair(A, b)) != bad.end()) {
            deleted.push_back(make_pair(A, b));
            bad.erase(make_pair(A, b));
          } else if (!check(A, b) && bad.find(make_pair(A, b)) == bad.end()) {
            added.push_back(make_pair(A, b));
            bad.insert(make_pair(A, b));
          }
        }
      find(d + 1);
      a[p.first + i][p.second + j] ^= 1;
      for (int i = 0; i < added.size(); i++) bad.erase(added[i]);
      for (int i = 0; i < deleted.size(); i++) bad.insert(deleted[i]);
    }
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (!check(i, j)) bad.insert(make_pair(i, j));
  ans = 1 << 30;
  find(0);
  if (ans >= 1 << 30)
    cout << -1;
  else
    cout << ans;
  return 0;
}
