#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, m, K;
int a[1005][1005], s[25][25], c[25];
int bin[2005];
long long dfs(int x, int y) {
  if (y == m + 1) x++, y = 1;
  if (x == n + 1) return 1;
  int t = s[x - 1][y] | s[x][y - 1];
  int res = 0, f = -1;
  for (int i = (1 << K) - 1 - t; i; i -= i & -i) {
    int u = bin[i & -i];
    if (a[x][y] != 0 && a[x][y] != u + 1) continue;
    s[x][y] = t | (1 << u);
    c[u]++;
    if (c[u] == 1) {
      if (f == -1) f = dfs(x, y + 1);
      res += f;
    } else
      res += dfs(x, y + 1);
    if (res >= 1000000007) res -= 1000000007;
    c[u]--;
  }
  return res;
}
int main() {
  n = read();
  m = read();
  K = read();
  if (n + m - 1 > K) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      a[i][j] = read();
      c[a[i][j] - 1]++;
    }
  for (int i = 0; i < K; i++) bin[1 << i] = i;
  printf("%I64d\n", dfs(1, 1));
  return 0;
}
