private int dfs(int[][] m, int[][] dp, int i, int j) {
        if (dp[i][j] != 0) return dp[i][j];
        int maxLen = 0;
        for (int k = 0; k < 4; ++k) {
            int x = i + dx[k], y = j + dy[k];
            if (x >= 0 && y >= 0 && x < m.length && y < m[0].length && m[x][y] > m[i][j]) {
                maxLen = Math.max(maxLen, dfs(m, dp, x, y));
            }
        }
        dp[i][j] = maxLen + 1;
        return dp[i][j];
    }