#include <bits/stdc++.h>
using namespace std;
void zgolemi(string &second, int k) {
  if (k == -1) {
    return;
  }
  if (second[k] == '1') {
    second[k] = '0';
    zgolemi(second, k - 1);
  } else {
    second[k]++;
  }
}
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  bool a[2 * n][2 * m];
  int redovi[n], koloni[m], br = 99999999;
  for (int i = 0; i < n; i++) {
    redovi[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    koloni[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int isto, razlicno, x;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      isto = 0, razlicno = 0;
      for (int k = 0; k < m; k++) {
        if (a[i][k] == a[j][k]) {
          isto++;
        } else {
          razlicno++;
        }
      }
      redovi[i] += min(isto, razlicno);
    }
    br = min(br, redovi[i]);
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      isto = 0, razlicno = 0;
      for (int k = 0; k < n; k++) {
        if (a[k][i] == a[k][j]) {
          isto++;
        } else {
          razlicno++;
        }
      }
      koloni[i] += min(isto, razlicno);
    }
    br = min(br, koloni[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int lq = 0; lq <= m; lq++) {
      x = 0;
      if (lq != 0) {
        a[i][lq - 1] = !a[i][lq - 1];
      }
      for (int j = 0; j < n; j++) {
        isto = 0, razlicno = 0;
        for (int k = 0; k < m; k++) {
          if (a[i][k] == a[j][k]) {
            isto++;
          } else {
            razlicno++;
          }
        }
        x += min(isto, razlicno);
      }
      if (br > x + 1) {
        br = x + 1;
      }
      if (lq != 0) {
        a[i][lq - 1] = !a[i][lq - 1];
      }
    }
  }
  for (int i = 0; i < m; i++) {
    for (int lq = 0; lq <= n; lq++) {
      x = 0;
      if (lq != 0) {
        a[lq - 1][i] = !a[lq - 1][i];
      }
      for (int j = 0; j < m; j++) {
        isto = 0, razlicno = 0;
        for (int k = 0; k < n; k++) {
          if (a[k][i] == a[k][j]) {
            isto++;
          } else {
            razlicno++;
          }
        }
        x += min(isto, razlicno);
      }
      if (br > x + 1) {
        br = x + 1;
      }
      if (lq != 0) {
        a[lq - 1][i] = !a[lq - 1][i];
      }
    }
  }
  if (br <= k) {
    cout << br << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
