#include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) {
  if (!a) return b;
  return GCD(b % a, a);
}
vector<vector<int> > transponse(const vector<vector<int> > &mat) {
  int n = mat.size(), m = mat[0].size();
  vector<vector<int> > retMat(m, vector<int>(n));
  for (int i = (0); i < (int)(m); i++)
    for (int j = (0); j < (int)(n); j++) {
      retMat[i][j] = mat[j][i];
    }
  return retMat;
}
int solve(vector<int> &b, vector<vector<int> > &mat) {
  int ret = 0;
  int n = mat.size(), m = mat[0].size();
  for (int i = (0); i < (int)(n); i++) {
    int ib = 0;
    int st0 = 0, st1 = 0;
    int sh0 = 0, sh1 = 1;
    for (int j = (0); j < (int)(m); j++) {
      if (j == b[ib]) {
        sh0 = !sh0;
        sh1 = !sh1;
        ib++;
      }
      if (mat[i][j] != sh0) st0++;
      if (mat[i][j] != sh1) st1++;
    }
    ret += min(st0, st1);
  }
  return ret;
}
int solveLarge(vector<vector<int> > &mat, int k) {
  int n = mat.size(), m = mat[0].size();
  int ret = k + 1;
  for (int i = (0); i < (int)(n); i++) {
    vector<int> border;
    for (int j = (1); j < (int)(m); j++) {
      if (mat[i][j] != mat[i][j - 1]) border.push_back(j);
    }
    border.push_back(m + 1);
    int res = solve(border, mat);
    ret = min(ret, res);
  }
  if (ret == k + 1) ret = -1;
  return ret;
}
int solveSmall(vector<vector<int> > &mat, int k) {
  int n = mat.size(), m = mat[0].size();
  int ret = k + 1;
  for (int i = (0); i < (int)((1 << n)); i++) {
    vector<int> border;
    for (int j = (0); j < (int)(n); j++) {
      if (i & (1 << j)) {
        border.push_back(j + 1);
      }
    }
    border.push_back(m + 1);
    int res = solve(border, mat);
    ret = min(ret, res);
  }
  if (ret == k + 1) ret = -1;
  return ret;
}
int main() {
  clock_t startTime = clock();
  ios_base::sync_with_stdio(false);
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int> > mat(n, vector<int>(m));
  for (int i = (0); i < (int)(n); i++)
    for (int j = (0); j < (int)(m); j++) {
      cin >> mat[i][j];
    }
  bool swapped = false;
  if (n < m) {
    swapped = true;
    swap(n, m);
    mat = transponse(mat);
  }
  int res = -1;
  if (n > 10) {
    res = solveLarge(mat, k);
  } else {
    res = solveSmall(mat, k);
  }
  cout << res << "\n";
  clock_t endTime = clock();
  cerr << "\nTime:" << double(endTime - startTime) / CLOCKS_PER_SEC
       << " seconds\n";
  return 0;
}
