#include <bits/stdc++.h>
using namespace std;
const int maxn = 20;
const int Mod = 1e9 + 7;
int n, m, k, c[maxn][maxn], f[maxn][maxn];
int v[maxn], lo[1 << maxn];
int dfs(int x, int y) {
  if (y > m) {
    x++;
    y = 1;
  }
  if (x > n) {
    return 1;
  }
  int s = f[x - 1][y] | f[x][y - 1], calk = -1, sum = 0;
  int S = ~s & ((1 << k) - 1);
  if (n + m - x - y + 1 > lo[S]) {
    return 0;
  }
  for (int col = 1; col <= k; col++) {
    if (S & (1 << (col - 1))) {
      if (c[x][y] == 0 || c[x][y] == col) {
        v[col]++;
        f[x][y] = s | (1 << (col - 1));
        if (v[col] == 1) {
          if (calk == -1) {
            calk = dfs(x, y + 1);
          }
          sum += calk;
        } else {
          sum += dfs(x, y + 1);
        }
        if (sum >= Mod) {
          sum -= Mod;
        }
        v[col]--;
      }
    }
  }
  return sum;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i < 1024; i++) {
    lo[i] = lo[i >> 1] + (i & 1);
  }
  if (n + m - 1 > k) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &c[i][j]);
      v[c[i][j]]++;
    }
  }
  printf("%d\n", dfs(1, 1));
  return 0;
}
