#include <bits/stdc++.h>
using namespace std;
long n, m, k;
vector<vector<long> > ar;
long color[11][11];
bool used[11];
bool no[11];
long long go(long r, long c) {
  if (c == m) {
    c = 0;
    r++;
  }
  if (r == n) {
    return 1LL;
  }
  if (c == m - 1 && r == n - 1 && n > 1 && m > 1) {
    if (color[ar[r][c]][r] < c || (r > 0 && color[ar[r][c]][r - 1] <= c)) {
      return 0LL;
    }
    return 1LL;
  }
  long long ret = 0LL;
  if (ar[r][c] != 0) {
    if (color[ar[r][c]][r] < c || (r > 0 && color[ar[r][c]][r - 1] <= c)) {
      return 0LL;
    }
    ret = go(r, c + 1) % 1000000007LL;
    return ret;
  } else {
    bool did = false;
    for (long i = 1; i <= k; i++) {
      if (color[i][r] <= c || no[i]) {
        continue;
      }
      if (color[i][n - 1] == 20 && !used[i]) {
        if (did) {
          continue;
        }
        did = true;
        long long total = 1LL;
        for (long j = i + 1; j <= k; j++) {
          if (!used[j] && color[j][n - 1] == 20) {
            total++;
          }
        }
        long og[n];
        for (long j = 0; j < n; j++) {
          og[j] = color[i][j];
        }
        for (long j = r; j < n; j++) {
          color[i][j] = min(color[i][j], c);
        }
        ret += total * go(r, c + 1);
        ret %= 1000000007LL;
        for (long j = r; j < n; j++) {
          color[i][j] = og[j];
        }
      } else {
        long og[n];
        for (long j = 0; j < n; j++) {
          og[j] = color[i][j];
        }
        for (long j = r; j < n; j++) {
          color[i][j] = min(color[i][j], c);
        }
        ret += go(r, c + 1);
        ret %= 1000000007LL;
        for (long j = r; j < n; j++) {
          color[i][j] = og[j];
        }
      }
    }
    return ret;
  }
}
int main() {
  for (long i = 0; i <= 10; i++) {
    used[i] = false;
    no[i] = false;
  }
  cin >> n >> m >> k;
  if (n + m - 1 > k) {
    cout << 0 << endl;
    return 0;
  }
  ar.resize(n);
  for (long a = 0; a <= 10; a++) {
    for (long b = 0; b <= 10; b++) {
      color[a][b] = 20;
    }
  }
  for (long i = 0; i < n; i++) {
    ar[i].resize(m);
    for (long j = 0; j < m; j++) {
      cin >> ar[i][j];
      if (ar[i][j] == 0) {
        continue;
      }
      for (long k = i; k < n; k++) {
        color[ar[i][j]][k] = min(color[ar[i][j]][k], j);
      }
      used[ar[i][j]] = true;
    }
  }
  long long mult = 1LL;
  if (n > 1 && m > 1) {
    if (ar[0][0] == 0) {
      long choose = 0;
      long op = 0;
      for (long i = 1; i <= k; i++) {
        if (!used[i]) {
          choose++;
          op = i;
        }
      }
      if (choose == 0) {
        cout << 0 << endl;
        return 0;
      }
      no[op] = true;
      mult *= choose;
      used[op] = true;
    }
    if (ar[n - 1][m - 1] == 0) {
      long choose = 0;
      long op = 0;
      for (long i = 1; i <= k; i++) {
        if (!used[i]) {
          choose++;
          op = i;
        }
      }
      if (choose == 0) {
        cout << 0 << endl;
        return 0;
      }
      no[op] = true;
      mult *= choose;
      used[op] = true;
    }
    no[ar[0][0]] = true;
    no[ar[n - 1][m - 1]] = true;
    long long ans = go(0, 1) % 1000000007LL;
    ans *= mult;
    ans %= 1000000007LL;
    cout << ans << endl;
    return 0;
  }
  long long ans = go(0, 0) % 1000000007LL;
  cout << ans << endl;
  return 0;
}
