#include <bits/stdc++.h>
using namespace std;
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
void bmax(int &a, int b) { a = (a > b) ? a : b; }
void bmin(int &a, int b) { a = (a < b) ? a : b; }
const int L = 1 << 20;
char buf[L], *p1, *p2;
int read() {
  int x = 0, w = 1;
  char ch = (p1 == p2 ? (p2 = buf + fread(p1 = buf, 1, L, stdin),
                         p1 == p2 ? EOF : *p1++)
                      : *p1++);
  while (ch > '9' || ch < '0') {
    if (ch == '-') w = -1;
    ch = (p1 == p2 ? (p2 = buf + fread(p1 = buf, 1, L, stdin),
                      p1 == p2 ? EOF : *p1++)
                   : *p1++);
  }
  while (ch <= '9' && ch >= '0')
    x = x * 10 + ch - '0',
    ch = (p1 == p2 ? (p2 = buf + fread(p1 = buf, 1, L, stdin),
                      p1 == p2 ? EOF : *p1++)
                   : *p1++);
  return x * w;
}
const int N = 1010, Mod = 1e9 + 7;
int n, m, k, mp[N][N], col[N];
int sta[N][N];
int BitCount(int S) {
  int res = 0;
  for (; S; S -= ((S) & (-S))) res++;
  return res;
}
void bmod(int &x, int y) {
  x += y - Mod;
  x += (x < 0) * Mod;
}
int DFS(int x, int y) {
  if (y == m + 1) x++, y = 1;
  if (x == n + 1) return 1;
  int S = sta[x - 1][y] | sta[x][y - 1];
  if (n - x + m - y - 1 > k - __builtin_popcount(S)) return 0;
  int fl = -1, res = 0, tmp;
  for (int i = 0; i < k; i++)
    if (!(S & (1 << i)) && (mp[x][y] == 0 || mp[x][y] == i + 1)) {
      col[i + 1]++;
      sta[x][y] = S | (1 << i);
      if (col[i + 1] == 1) {
        if (~fl)
          bmod(res, fl);
        else
          fl = DFS(x, y + 1), bmod(res, fl);
      } else
        tmp = DFS(x, y + 1), bmod(res, tmp);
      col[i + 1]--;
    }
  return res;
}
int main() {
  n = read();
  m = read();
  k = read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      mp[i][j] = read();
      if (mp[i][j]) col[mp[i][j]]++;
    }
  if (n + m - 1 > k)
    puts("0");
  else
    printf("%d\n", DFS(1, 1));
  return 0;
}
