#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int mat[105][105];
int n, m, k;
int best = INF;
set<pair<int, int>> bad;
bool check(int x, int y) {
  if (x < 0 || y < 0 || x + 1 >= n || y + 1 >= m) {
    return true;
  }
  int numZero = 0;
  for (int i = 0; i <= 1; ++i) {
    for (int j = 0; j <= 1; ++j) {
      numZero += (mat[x + i][y + j] == 0 ? 1 : 0);
    }
  }
  if (numZero % 2 == 0) {
    return true;
  } else {
    return false;
  }
}
void printBad() {
  cout << "Set(" << (int)bad.size() << "): ";
  for (auto x : bad) {
    cout << "(" << x.first << "," << x.second << ") ";
  }
  cout << "\n";
}
void rek(int cost) {
  if (bad.size() == 0) {
    best = min(best, cost);
    return;
  }
  if (cost >= k) return;
  pair<int, int> sq = *bad.begin();
  for (int i = 0; i <= 1; ++i) {
    for (int j = 0; j <= 1; ++j) {
      int cx = sq.first + i;
      int cy = sq.second + j;
      mat[cx][cy] ^= 1;
      vector<pair<int, int>> added;
      vector<pair<int, int>> deleted;
      for (int l = -1; l <= 0; ++l) {
        for (int m = -1; m <= 0; ++m) {
          int asx = cx + l;
          int asy = cy + m;
          if (check(asx, asy) && bad.find({asx, asy}) != bad.end()) {
            bad.erase({asx, asy});
            deleted.push_back({asx, asy});
          } else if (!check(asx, asy) && bad.find({asx, asy}) == bad.end()) {
            bad.insert({asx, asy});
            added.push_back({asx, asy});
          }
        }
      }
      rek(cost + 1);
      mat[cx][cy] ^= 1;
      for (auto z : added) {
        bad.erase(z);
      }
      for (auto z : deleted) {
        bad.insert(z);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> mat[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (!check(i, j)) bad.insert({i, j});
    }
  }
  rek(0);
  cout << (best == INF ? -1 : best) << "\n";
  return 0;
}
