#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
template <typename T>
void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) {
    write(x / 10);
  }
  putchar(x % 10 + '0');
}
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= f;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; };
long long ksm(long long a, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1) ans = ((ans % mod) * (a % mod)) % mod;
    a = ((a % mod) * (a % mod)) % mod;
    n >>= 1;
  }
  return ans % mod;
}
const int maxn = 1000 + 100;
int n, m, k;
int mp[maxn][maxn];
int f[maxn][maxn];
int c[maxn];
inline int cal(int x) {
  long long cnt = 0;
  for (register int i = 1; i <= k; ++i) {
    if (!(x & (1 << i))) cnt++;
  }
  return cnt;
}
long long solve(int x, int y) {
  if (x > n) return 1;
  int nxtx = x, nxty = y + 1;
  if (nxty > m) nxty %= m, nxtx += 1;
  int flag = 0;
  long long tmp = 0;
  f[x][y] = (f[x - 1][y] | f[x][y - 1]);
  int num = cal(f[x][y]);
  if (num < n - x + m - y + 1) return 0;
  long long res = 0;
  if (mp[x][y]) {
    if (!(f[x][y] & (1 << mp[x][y]))) {
      f[x][y] |= (1 << mp[x][y]);
      res = (res + solve(nxtx, nxty)) % mod;
      f[x][y] ^= (1 << mp[x][y]);
    }
  } else {
    for (register int i = 1; i <= k; ++i) {
      if (!(f[x][y] & (1 << i))) {
        if (c[i] == 0) {
          if (flag) {
            res += tmp;
            res %= mod;
          } else {
            flag = 1;
            c[i]++;
            f[x][y] |= (1 << i);
            tmp = solve(nxtx, nxty);
            f[x][y] ^= (1 << i);
            c[i]--;
            res += tmp;
            res %= mod;
          }
        } else {
          c[i]++;
          f[x][y] |= (1 << i);
          res += solve(nxtx, nxty);
          f[x][y] ^= (1 << i);
          c[i]--;
          res %= mod;
        }
      }
    }
  }
  return res;
}
int main() {
  clock_t c1 = clock();
  read(n), read(m), read(k);
  for (register int i = 1; i <= n; ++i)
    for (register int j = 1; j <= m; ++j)
      read(mp[i][j]), mp[i][j] ? c[mp[i][j]]++ : 23333;
  if (n + m - 1 > k) {
    puts("0");
    return 0;
  }
  long long ans = solve(1, 1);
  write(ans);
  std::cerr << "Time:" << clock() - c1 << "ms" << std::endl;
  return 0;
}
