#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m, k;
int a[1005][1005], s[20][20];
int b[1 << 10], c[20];
int dfs(int x, int y) {
  if (y > m) x++, y = 1;
  if (x > n) return 1;
  int stu = s[x - 1][y] | s[x][y - 1];
  int ret = 0;
  int w = -1;
  for (int i = (~stu & ((1 << k) - 1)); i; i -= (i & (-i))) {
    int u = b[i & (-i)];
    if (a[x][y] != 0 && a[x][y] != u + 1) continue;
    s[x][y] = stu | (1 << u);
    c[u]++;
    if (c[u] == 1) {
      if (w == -1) w = dfs(x, y + 1);
      ret += w;
      if (ret >= mod) ret -= mod;
    } else {
      ret += dfs(x, y + 1);
      if (ret >= mod) ret -= mod;
    }
    c[u]--;
  }
  return ret;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  memset(c, 0, sizeof(c));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      c[a[i][j] - 1]++;
    }
  if (n + m - 1 > k) {
    puts("0");
    return 0;
  }
  memset(s, 0, sizeof(s));
  for (int i = 0; i < k; i++) b[1 << i] = i;
  cout << dfs(1, 1) << endl;
}
