#include <bits/stdc++.h>
using namespace std;
template <typename comparable>
void readint(comparable& x) {
  comparable num = 0, fix = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') fix = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    num = (num << 3) + (num << 1) + (ch ^ '0');
    ch = getchar();
  }
  x = num * fix;
}
const int mod = 1e9 + 7;
int cnt[1024], bin[15];
int N, M, K;
int vis[15];
int arr[1005][1005];
int sta[1005][1005];
long long dfs(int x, int y) {
  if (y == M + 1) x = x + 1, y = 1;
  if (x == N + 1) return 1;
  int S = 0;
  if (x != 1) S |= sta[x - 1][y];
  if (y != 1) S |= sta[x][y - 1];
  int T = (~S) & (bin[K] - 1);
  long long temp = -1, res = 0;
  if (cnt[T] < N - x + M - y + 1) return 0;
  for (int i = 0; i < K; i++)
    if (T & bin[i]) {
      int c = i + 1;
      if (arr[x][y] != 0 && arr[x][y] != c) continue;
      vis[c]++, sta[x][y] = S | bin[i];
      if (vis[c] == 1) {
        if (temp == -1) temp = dfs(x, y + 1);
        (res += temp) %= mod;
      } else
        (res += dfs(x, y + 1)) %= mod;
      vis[c]--;
    }
  return res;
}
int main(int argc, char* argv[]) {
  for (register int i = 1; i <= 1023; i++) cnt[i] = cnt[i >> 1] + (i & 1);
  bin[0] = 1;
  for (register int i = 1; i <= 10; i++) bin[i] = bin[i - 1] << 1;
  readint(N), readint(M), readint(K);
  for (register int i = 1; i <= N; i++)
    for (register int j = 1; j <= M; j++) {
      readint(arr[i][j]);
      if (arr[i][j]) vis[arr[i][j]]++;
    }
  if (N + M - 1 > K)
    printf("0");
  else
    cout << dfs(1, 1);
  return 0;
}
