#include <bits/stdc++.h>
using namespace std;
const int NN = 12, SS = 1030, tt = 1000000007;
int n, m, k, maxs, who[SS], cnt[NN], f[NN][NN], col[NN][NN];
int dfs(int x, int y) {
  if (y > m) x++, y = 1;
  if (x > n) return 1;
  int s = f[x - 1][y] | f[x][y - 1], fst = -1, res = 0;
  for (int ss = maxs & ~s; ss; ss -= ss & -ss) {
    int i = who[ss & -ss];
    if (col[x][y] && col[x][y] != i) continue;
    cnt[i]++;
    f[x][y] = s | (1 << i - 1);
    if (cnt[i] == 1 && fst < 0) fst = dfs(x, y + 1);
    res += (cnt[i] == 1 ? fst : dfs(x, y + 1));
    if (res >= tt) res -= tt;
    cnt[i]--;
  }
  return res;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  if (k < n + m - 1) {
    printf("0\n");
    return 0;
  }
  maxs = (1 << k) - 1;
  for (int i = (1); i <= (k); i++) who[1 << i - 1] = i;
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (m); j++) {
      scanf("%d", &col[i][j]);
      if (col[i][j]) cnt[col[i][j]]++;
    }
  printf("%d\n", dfs(1, 1));
  return 0;
}
