#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  register int x = 0, w = 0;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return w ? -x : x;
}
const int N = 1010;
const int Mod = 1e9 + 7;
int n, m, k, cnt, used[21], Lg[1 << 12], a[N][N], f[20][20];
int dfs(int x, int y) {
  if (y == m + 1) ++x, y = 1;
  if (x == n + 1) return 1;
  register int i, id, now, fnow, cnt = 0, ans = 0, res = -1;
  now = f[x - 1][y] | f[x][y - 1];
  fnow = (~now) & ((1 << k) - 1);
  for (i = fnow; i; i ^= i & (-i)) ++cnt;
  if (cnt < n + m - x - y + 1) return 0;
  for (i = fnow; i; i ^= i & (-i)) {
    id = Lg[i & (-i)];
    if (a[x][y] == 0 || a[x][y] == id) {
      ++used[id], f[x][y] = now | (1 << (id - 1));
      if (used[id] == 1) {
        if (res == -1) res = dfs(x, y + 1);
        ans += res;
      } else
        ans += dfs(x, y + 1);
      if (ans >= Mod) ans -= Mod;
      --used[id];
    }
  }
  return ans;
}
int main() {
  int i, j;
  n = gi(), m = gi(), k = gi();
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) a[i][j] = gi(), used[a[i][j]] += (a[i][j] > 0);
  if (n + m - 1 > k) {
    putchar('0');
    return 0;
  }
  for (i = 1; i <= k; ++i) Lg[1 << (i - 1)] = i;
  printf("%d\n", dfs(1, 1));
  return 0;
}
