#include using namespace std; #define all(a) (a).begin(), (a).end() using ll = long long; using ull = unsigned long long; using vll = vector; ull bit(int n) { return 1ull << n; } ll sign(ll a) { return (a > 0) - (a < 0); } ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } ll cdiv(ll a, ll b) { return -fdiv(-a, b); } constexpr ll DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; constexpr ll DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; template using priority_queue_rev = priority_queue, greater>; template T sq(const T &a) { return a * a; } template bool chmax(T &a, const U &b) { return ((a < b) ? (a = b, true) : (false)); } template bool chmin(T &a, const U &b) { return ((a > b) ? (a = b, true) : (false)); } template ostream &operator<<(ostream &os, const vector &a) { os << "("; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << ")"; return os; } #ifdef ONLINE_JUDGE #define dump(...) (void(0)) #else void debug() { cerr << endl; } template void debug(Head &&head, Tail &&... tail) { cerr << head; if (sizeof...(Tail)) cerr << ", "; debug(tail...); } #define dump(...) cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ", debug(__VA_ARGS__) #endif struct rep { struct itr { int v; itr(int v) : v(v) {} void operator++() { ++v; } int operator*() const { return v; } bool operator!=(const itr &i) const { return v != i.v; } }; int l, r; rep(int r) : l(min(0, r)), r(r) {} rep(int l, int r) : l(min(l, r)), r(r) {} itr begin() const { return l; }; itr end() const { return r; }; }; struct per { struct itr { int v; itr(int v) : v(v) {} void operator++() { --v; } int operator*() const { return v; } bool operator!=(const itr &i) const { return v != i.v; } }; int l, r; per(int r) : l(min(0, r)), r(r) {} per(int l, int r) : l(min(l, r)), r(r) {} itr begin() const { return r - 1; }; itr end() const { return l - 1; }; }; ll MOD; struct modint { ll val; modint(ll val = 0) : val(val >= 0 ? val % MOD : (MOD - (-val) % MOD) % MOD) {} static ll mod() { return MOD; } modint inv() const { ll a = val, b = MOD, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return modint(u); } modint pow(ll k) const { modint ret = 1, mul = val; while (k) { if (k & 1) ret *= mul; mul *= mul; k >>= 1; } return ret; } modint &operator+=(const modint &a) { if ((val += a.val) >= MOD) val -= MOD; return *this; } modint &operator-=(const modint &a) { if ((val += MOD - a.val) >= MOD) val -= MOD; return *this; } modint &operator*=(const modint &a) { (val *= a.val) %= MOD; return *this; } modint &operator/=(const modint &a) { return *this *= a.inv(); } bool operator==(const modint &a) const { return val == a.val; } bool operator!=(const modint &a) const { return rel_ops::operator!=(*this, a); } modint operator+() const { return *this; } modint operator-() const { return modint(-val); } friend modint operator+(const modint &a, const modint &b) { return modint(a) += b; } friend modint operator-(const modint &a, const modint &b) { return modint(a) -= b; } friend modint operator*(const modint &a, const modint &b) { return modint(a) *= b; } friend modint operator/(const modint &a, const modint &b) { return modint(a) /= b; } friend istream &operator>>(istream &is, modint &a) { ll val; is >> val; a = modint(val); return is; } friend ostream &operator<<(ostream &os, const modint &a) { return os << a.val; } }; using mint = modint; template struct combination { vector fact, finv, inv; combination(int n) : fact(n + 1), finv(n + 1), inv(n + 1) { fact[0] = fact[1] = finv[0] = finv[1] = inv[1] = 1; for (int i : rep(2, n + 1)) { fact[i] = fact[i - 1] * i; inv[i] = -inv[mint::mod() % i] * (mint::mod() / i); finv[i] = finv[i - 1] * inv[i]; } } mint P(int n, int r) { return r < 0 || n < r ? 0 : (fact[n] * finv[n - r]); } mint C(int n, int r) { return P(n, r) * finv[r]; } mint H(int n, int r) { return C(n + r - 1, r); } mint catalan(int n) { return C(2 * n, n) / (n + 1); } }; int main() { ll h, w, n; cin >> h >> w >> n; vector c(h, vll(w)); for (ll i : rep(h)) { for (ll j : rep(w)) cin >> c[i][j]; } vector dp(h, vll(w, -1)); auto rec = [&](auto rec, ll y, ll x) -> ll { if (dp[y][x] != -1) return dp[y][x]; ll lb = 1; for (ll k : rep(4)) { ll ny = y + DY[k], nx = x + DX[k]; if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue; if (c[y][x] < c[ny][nx]) chmax(lb, rec(rec, ny, nx) + 1); } return dp[y][x] = lb; }; ll ans = 0; for (ll i : rep(h)) { for (ll j : rep(w)) rec(rec, i, j), chmax(ans, dp[i][j]); } cout << ans << endl; }