import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val m = nextInt() val q = nextInt() val adj = Array(q) { mutableListOf() } val data = Array(q) { nextInt() to nextInt() } for (i in 0 until q) { for (j in 0 until q) { if (data[i].first < data[j].first && data[i].second < data[j].second) { adj[i].add(j) } } } val dp = IntArray(q) { -1 } fun dfs(v: Int): Int { if (dp[v] != -1) return dp[v] var max = 0 for (w in adj[v]) { max = maxOf(max, dfs(w)) } dp[v] = max + 1 return dp[v] } (0 until q).forEach { dfs(it) } println(dp.maxOrNull()) } fun main() { Thread(null, { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() }, "solve", 1.shl(26)) .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } } .apply { start() }.join() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() // endregion