#include <bits/stdc++.h>
using namespace std;
namespace io {
const int SIZ = 1 << 21 | 1;
char *iS, *iT, ibuff[SIZ], obuff[SIZ], *oS = obuff, *oT = oS + SIZ - 1, fu[110],
                                       c;
int fr;
inline void out() {
  fwrite(obuff, 1, oS - obuff, stdout);
  oS = obuff;
}
template <class Type>
inline void read(Type& x) {
  x = 0;
  Type dep = 1;
  for (c = (iS == iT ? (iT = (iS = ibuff) + fread(ibuff, 1, SIZ, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       (c > '9' || c < '0') && c != '-';
       c = (iS == iT ? (iT = (iS = ibuff) + fread(ibuff, 1, SIZ, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    ;
  c == '-' ? dep = -1 : x = (c & 15);
  for (c = (iS == iT ? (iT = (iS = ibuff) + fread(ibuff, 1, SIZ, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       c >= '0' && c <= '9';
       c = (iS == iT ? (iT = (iS = ibuff) + fread(ibuff, 1, SIZ, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = x * 10 + (c & 15);
  x *= dep;
}
inline void readc(char& x, int pd = 1) {
  if (pd)
    for (x = (iS == iT ? (iT = (iS = ibuff) + fread(ibuff, 1, SIZ, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++);
         (x == ' ' || x == '\n' || x == '\r' || x == 't') && x != EOF;
         x = (iS == iT ? (iT = (iS = ibuff) + fread(ibuff, 1, SIZ, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++))
      ;
  else
    x = (iS == iT ? (iT = (iS = ibuff) + fread(ibuff, 1, SIZ, stdin),
                     (iS == iT ? EOF : *iS++))
                  : *iS++);
}
template <class Type>
inline void print(Type x, char text = '\n') {
  if (x < 0) *oS++ = '-', x *= -1;
  if (x == 0) *oS++ = '0';
  while (x) fu[++fr] = x % 10 + '0', x /= 10;
  while (fr) *oS++ = fu[fr--];
  *oS++ = text;
  out();
}
inline void prints(char x[], char text = '\n') {
  for (register int i = 0; x[i]; ++i) *oS++ = x[i];
  *oS++ = text;
  out();
}
}  // namespace io
using namespace io;
const int mod = 1e9 + 7;
const int maxn = 1080, maxk = 15;
int n, m, k;
int a[maxn], v[maxk];
int t[maxk][maxk], s[maxk][maxk];
int dfs(int x, int dep) {
  if (dep == m + 1) ++x, dep = 1;
  if (x == n + 1) return 1;
  int sum = s[x - 1][dep] | s[x][dep - 1];
  int sum2 = ~sum & ((1 << k) - 1);
  if (n + m - x - dep + 1 > a[sum2]) return 0;
  int mem = -1;
  int ans = 0;
  for (register int i = 0; i < k; ++i)
    if (sum2 & (1 << i))
      if (t[x][dep] == 0 || t[x][dep] == i + 1) {
        v[i + 1]++;
        s[x][dep] = sum | (1 << i);
        if (v[i + 1] == 1) {
          if (mem == -1) mem = dfs(x, dep + 1);
          ans += mem;
        } else
          ans += dfs(x, dep + 1);
        ans %= mod;
        --v[i + 1];
      }
  return ans;
}
int main() {
  for (register int i = 1; i < 1 << 10; ++i) a[i] = a[i >> 1] + (i & 1);
  read(n);
  read(m);
  read(k);
  if (n + m - 1 > k) {
    print(0);
    return 0;
  }
  for (register int i = 1; i <= n; ++i)
    for (register int e = 1; e <= m; ++e) read(t[i][e]), ++v[t[i][e]];
  print(dfs(1, 1));
  return 0;
}
