#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const long long MOD = 1e9 + 7;
int n, m, k;
int a[N][N];
int f[15][15];
int used[12];
inline int read() {
  char ch = getchar();
  while (ch == ' ' || ch == '\n') ch = getchar();
  int res = 0;
  while (ch >= '0' && ch <= '9')
    res = (res << 1) + (res << 3) + ch - '0', ch = getchar();
  return res;
}
inline int Count(int x) {
  int num = 0;
  for (int i = 0; i < k; ++i)
    if (((x >> i) & 1)) num++;
  return num;
}
int dfs(int x, int y) {
  if (y == m + 1) x++, y = 1;
  if (x == n + 1) return 1;
  f[x][y] = f[x - 1][y] | f[x][y - 1];
  if (Count(f[x][y]) + n - x + m - y + 1 > k) return 0;
  if (a[x][y]) {
    if (((f[x][y] >> a[x][y] - 1) & 1)) return 0;
    f[x][y] |= (1 << (a[x][y] - 1));
    return dfs(x, y + 1);
  }
  int ret = 0;
  int tmp = -1;
  for (int i = 0; i < k; ++i)
    if (!((f[x][y] >> i) & 1)) {
      if (used[i + 1]) {
        f[x][y] |= (1 << i);
        ret += dfs(x, y + 1);
        f[x][y] ^= (1 << i);
      } else {
        if (tmp != -1)
          ret += tmp;
        else {
          used[i + 1]++;
          f[x][y] |= (1 << i);
          tmp = dfs(x, y + 1);
          ret += tmp;
          f[x][y] ^= (1 << i);
          used[i + 1]--;
        }
      }
      ret %= MOD;
    }
  return ret;
}
int main() {
  n = read();
  m = read();
  k = read();
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) a[i][j] = read(), used[a[i][j]]++;
  if (n + m - 1 > k) {
    puts("0");
    return 0;
  }
  printf("%d\n", dfs(1, 1));
}
