#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void minu(T& x, T y) {
  x = min(x, y);
}
template <class T>
inline void maxu(T& x, T y) {
  x = max(x, y);
}
inline long long bit(long long n) { return 1LL << n; }
template <class T>
ostream& operator<<(ostream& os, vector<T> x) {
  for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
    os << *it << ' ';
  return os;
}
long long dx[8] = {1, -1, 0, 0, -1, 1, 1, -1};
long long dy[8] = {0, 0, 1, -1, -1, 1, -1, 1};
int dist(const vector<int>& p, const vector<int>& q) {
  int ret = 0;
  for (long long i = 0; i < ((long long)p.size()); ++i) ret += p[i] ^ q[i];
  return ret;
}
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int> > b(min(n, m), vector<int>(max(n, m), 0));
  if (n > m) {
    for (long long i = 0; i < ((long long)n); ++i)
      for (long long j = 0; j < ((long long)m); ++j) cin >> b[j][i];
    swap(n, m);
  } else {
    for (long long i = 0; i < ((long long)n); ++i)
      for (long long j = 0; j < ((long long)m); ++j) cin >> b[i][j];
  }
  int ans = 11;
  if (n > 10) {
    for (long long i = 0; i < ((long long)n); ++i) {
      int tans = 0;
      for (long long j = 0; j < ((long long)n); ++j) {
        int d = dist(b[i], b[j]);
        tans += min(d, m - d);
      }
      minu(ans, tans);
    }
  } else {
    vector<int> cols(m, 0);
    for (long long i = 0; i < ((long long)n); ++i)
      for (long long j = 0; j < ((long long)m); ++j)
        cols[j] |= bit(i) * b[i][j];
    for (int mask = 0; mask < bit(n); ++mask) {
      int tans = 0;
      for (__typeof((cols).begin()) col = (cols).begin(); col != (cols).end();
           col++) {
        int d = __builtin_popcountll(*col ^ mask);
        tans += min(d, n - d);
      }
      minu(ans, tans);
    }
  }
  if (ans > k) ans = -1;
  cout << ans << endl;
  return 0;
}
