#include <bits/stdc++.h>
using namespace std;
int n, m, k, f[1005][1005], a[1005][1005], cnt[1100], num[11];
template <typename T>
inline T read() {
  T x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * w;
}
int dis(int x, int y) { return n - x + m - y + 1; }
int dfs(int x, int y) {
  if (y == m + 1) return dfs(x + 1, 1);
  if (x == n + 1) return 1;
  f[x][y] = f[x - 1][y] | f[x][y - 1];
  int tmp = cnt[f[x][y]], res = 0;
  if (a[x][y]) {
    tmp = (1 << (a[x][y] - 1));
    if (f[x][y] & tmp) return 0;
    f[x][y] |= tmp, res = dfs(x, y + 1), f[x][y] ^= tmp;
    return res;
  }
  if (dis(x, y) > k - tmp) return 0;
  tmp = -1;
  for (int i = 0; i < k; i++)
    if (!(f[x][y] & (1 << i))) {
      f[x][y] |= (1 << i), num[i + 1]++;
      if (num[i + 1] == 1) {
        if (tmp == -1)
          res = 1ll * (res + (tmp = dfs(x, y + 1))) % 1000000007;
        else
          res = (1ll * res + tmp) % 1000000007;
      } else {
        res = (1ll * res + dfs(x, y + 1)) % 1000000007;
      }
      f[x][y] ^= (1 << i), num[i + 1]--;
    }
  return res;
}
int main() {
  n = read<int>(), m = read<int>(), k = read<int>();
  for (int i = 1; i <= 1024; i++) cnt[i] = cnt[i - (i & (-i))] + 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      a[i][j] = read<int>();
      if (a[i][j]) num[a[i][j]]++, f[i][j] |= (1 << (a[i][j] - 1));
    }
  if (n + m - 1 > k) {
    puts("0");
    return 0;
  }
  printf("%d\n", dfs(1, 1));
  return 0;
}
