#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
int n, m, k;
int a[12][12];
int f[12][12], g[12][12];
int cnt[12];
long long dfs(int i, int j) {
  if (j > m) {
    i++;
    j = 1;
  }
  if (i > n) {
    return 1;
  }
  f[i][j] = f[i - 1][j] | f[i][j - 1];
  if (f[i][j] & g[i][j]) {
    return 0;
  }
  int S = f[i][j];
  int z = 0;
  for (int t = 1; t <= k; t++) {
    if (!(S >> t & 1)) {
      z++;
    }
  }
  if ((n - i) + (m - j) + 1 > z) {
    return 0;
  }
  if (a[i][j]) {
    f[i][j] = f[i][j] | 1 << a[i][j];
    return dfs(i, j + 1);
  }
  S = S | g[i][j];
  long long res = 0, tmp = 0;
  bool flag = false;
  for (int t = 1; t <= k; t++) {
    if (!(S >> t & 1)) {
      cnt[t]++;
      f[i][j] = f[i][j] | 1 << t;
      if (cnt[t] == 1) {
        if (!flag) {
          flag = true;
          tmp = dfs(i, j + 1);
        }
        res = (res + tmp) % mod;
      } else {
        res = (res + dfs(i, j + 1)) % mod;
      }
      cnt[t]--;
      f[i][j] = f[i][j] & ~(1 << t);
    }
  }
  return res;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  if (n + m - 1 > k) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      cnt[a[i][j]]++;
    }
  }
  for (int i = n; i > 0; i--) {
    for (int j = m; j > 0; j--) {
      g[i][j] = g[i + 1][j] | g[i][j + 1];
      if (a[i][j] && g[i][j] >> a[i][j] & 1) {
        printf("0\n");
        return 0;
      }
      if (a[i][j]) g[i][j] = g[i][j] | 1 << a[i][j];
    }
  }
  printf("%I64d\n", dfs(1, 1));
  return 0;
}
