#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
int a[1005][1005], f[1005][1005], n, m, k, ans, vis[15];
int get(int x) {
  int tot = 0;
  while (x) {
    ++tot;
    x = (x - 1) & x;
  }
  return tot;
}
int dfs(int x, int y) {
  if (y > m) y = 1, ++x;
  if (x > n) return 1;
  int s = f[x - 1][y] | f[x][y - 1], can = k - get(s);
  if (n + m - x - y + 1 > can) return 0;
  int tot = -1, ans = 0;
  for (int i = 1; i <= k; ++i) {
    if ((s & (1 << i - 1)) == 0) {
      if (a[x][y] == i || a[x][y] == 0) {
        f[x][y] = s | (1 << i - 1);
        ++vis[i];
        if (vis[i] == 1) {
          if (tot == -1) tot = dfs(x, y + 1) % mo;
          ans = (ans + tot) % mo;
        } else
          ans = (ans + dfs(x, y + 1)) % mo;
        --vis[i];
      }
    }
  }
  return ans;
}
int main() {
  n = read(), m = read(), k = read();
  if (n + m - 1 > k) {
    putchar('0');
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) a[i][j] = read(), vis[a[i][j]] += 1;
  cout << dfs(1, 1);
  return 0;
}
