#include <bits/stdc++.h>
using namespace std;
const int N = 205;
int le[N], ri[N], a[N][N], s[N][N];
int solve(int dem, int n, int m, int k) {
  int f = 0;
  for (int i = 1; i <= m; i++) {
    int ans0 = 0, ans1 = 0;
    bool zero = true;
    for (int j = 0; j < dem; j++) {
      int tmp =
          s[ri[j]][i] - s[ri[j]][i - 1] - s[le[j] - 1][i] + s[le[j] - 1][i - 1];
      if (zero)
        ans0 += tmp;
      else
        ans0 += (ri[j] - le[j] + 1) - tmp;
      if (zero)
        ans1 += (ri[j] - le[j] + 1) - tmp;
      else
        ans1 += tmp;
      zero = !zero;
    }
    f += min(ans1, ans0);
    if (f > k) return k + 1;
  }
  return f;
}
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (n > m)
        scanf("%d", &a[j][i]);
      else
        scanf("%d", &a[i][j]);
  if (n > m) swap(n, m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      s[i][j] = s[i - 1][j] + s[i][j - 1] + a[i][j] - s[i - 1][j - 1];
  int ans = k + 1;
  if (n <= 10) {
    int maxv = (1 << n);
    for (int ch = 0; ch < maxv; ch++) {
      int dem = 0;
      int tmp = ch;
      for (int i = 0; i < n;) {
        int val = (tmp & 1);
        le[dem] = i + 1;
        ri[dem] = i;
        while (i < n && (tmp & 1) == val) {
          tmp >>= 1;
          ri[dem]++;
          i++;
        }
        dem++;
      }
      ans = min(ans, solve(dem, n, m, k));
    }
  } else {
    for (int j = 1; j <= m; j++) {
      int dem = 0;
      for (int i = 1; i <= n;) {
        int val = a[i][j];
        le[dem] = i;
        ri[dem] = i - 1;
        while (i <= n && a[i][j] == val) {
          ri[dem]++;
          i++;
        }
        dem++;
      }
      ans = min(ans, solve(dem, n, m, k));
    }
  }
  if (ans > k)
    printf("-1");
  else
    printf("%d", ans);
}
