#include <bits/stdc++.h>
using namespace std;
int b[150][150];
int a[150][150];
int n, m, T, ans;
void Slove() {
  if (n > T) {
    int output = 0x3f3f3f3f;
    for (int z = 1; z <= n; z++) {
      int sum = 0;
      for (int i = 1; i <= n; i++) {
        int cnt = 0;
        for (int j = 1; j <= m; j++) {
          if (a[i][j] != a[z][j]) cnt++;
        }
        int cnt2 = 0;
        for (int j = 1; j <= m; j++) {
          if (a[i][j] == a[z][j]) cnt2++;
        }
        sum += min(cnt, cnt2);
      }
      output = min(output, sum);
    }
    ans = min(ans, output);
  } else if (m <= T) {
    int output = 0x3f3f3f3f;
    for (int z = 0; z < (1 << T); z++) {
      int sum = 0;
      for (int i = 2; i <= n; i++) {
        int cnt = 0;
        for (int j = 1; j <= m; j++) {
          if ((z & (1 << (j - 1))) > 0) {
            if (a[i][j] == a[1][j]) cnt++;
          } else if (a[i][j] != a[1][j])
            cnt++;
        }
        int cnt2 = 0;
        for (int j = 1; j <= m; j++) {
          if ((z & (1 << (j - 1))) > 0) {
            if (a[i][j] != a[1][j]) cnt2++;
          } else if (a[i][j] == a[1][j])
            cnt2++;
        }
        sum += min(cnt, cnt2);
      }
      int temp = 0;
      for (int i = 1; i <= m; i++) {
        if ((z & (1 << (i - 1))) > 0) temp++;
      }
      output = min(output, sum + temp);
    }
    ans = min(ans, output);
  }
}
int main() {
  while (~scanf("%d%d%d", &n, &m, &T)) {
    ans = 0x3f3f3f3f;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        scanf("%d", &a[i][j]);
        b[i][j] = a[i][j];
      }
    }
    Slove();
    int x = 1, y = 1;
    for (int i = 1; i <= m; i++) {
      for (int j = n; j >= 1; j--) {
        a[x][y] = b[j][i];
        y++;
        if (y > n) y = 1, x++;
      }
    }
    swap(n, m);
    Slove();
    if (ans > T)
      printf("-1\n");
    else
      printf("%d\n", ans);
  }
}
