#include <bits/stdc++.h>
using namespace std;
int n, m, K;
int a[101][101], b[101][101];
int f[101][11], g[101][11];
int aa[11][11];
int pd(int i, int j, int x, int y) {
  int ans = 0;
  for (int k = 1; k <= m; ++k)
    if ((x ^ y) != (a[i][k] ^ a[j][k])) ++ans;
  return ans;
}
int solve() {
  int ans = 100;
  for (int I = 1; I <= n; ++I) {
    memset(f, 63, sizeof(f));
    memset(g, 63, sizeof(g));
    f[I][0] = 0;
    g[I][0] = 0;
    for (int i = I + 1; i <= n; ++i)
      for (int M = 0; M <= 1; ++M) {
        int t = pd(I, i, a[I][1], M);
        for (int j = 0; j <= K - t; ++j)
          f[i][j + t] = min(f[i][j + t], f[i - 1][j] + t);
      }
    for (int i = I - 1; i > 0; --i)
      for (int M = 0; M <= 1; ++M) {
        int t = pd(I, i, a[I][1], M);
        for (int j = 0; j <= K - t; ++j)
          g[i][j + t] = min(g[i][j + t], g[i + 1][j] + t);
      }
    for (int j = 0; j <= K; ++j)
      for (int k = 0; k <= K - j; ++k) {
        ans = min(ans, g[1][j] + f[n][k]);
      }
  }
  if (ans > K) return -1;
  return ans;
}
int main() {
  scanf("%d%d%d", &n, &m, &K);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) scanf("%d", &a[i][j]);
  if (n < m) {
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) b[j][i] = a[i][j];
    swap(n, m);
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) a[i][j] = b[i][j];
  }
  if (n > K) {
    printf("%d\n", solve());
    return 0;
  }
  int ans = 100;
  for (int opt = 0; opt < (1 << m); ++opt) {
    for (int i = 1; i <= m; ++i) aa[1][i] = (opt >> (i - 1)) & 1;
    int ans1 = 0;
    for (int i = 1; i <= m; ++i)
      if (a[1][i] != aa[1][i]) ++ans1;
    if (ans1 > K) continue;
    for (int i = 1; i <= m; ++i) swap(a[1][i], aa[1][i]);
    memset(f, 63, sizeof(f));
    f[1][0] = 0;
    for (int i = 2; i <= n; ++i)
      for (int M = 0; M <= 1; ++M) {
        int t = pd(1, i, a[1][1], M);
        for (int j = 0; j <= K - t; ++j)
          f[i][j + t] = min(f[i][j + t], f[i - 1][j] + t);
      }
    for (int j = 0; j <= K - ans1; ++j) ans = min(ans, f[n][j] + ans1);
    for (int i = 1; i <= m; ++i) swap(a[1][i], aa[1][i]);
  }
  if (ans > K) ans = -1;
  printf("%d\n", ans);
}
