fn main() { let mut nmq = String::new(); std::io::stdin().read_line(&mut nmq).ok(); let nmq: Vec = nmq.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nmq[0]; let m = nmq[1]; let q = nmq[2]; let mut checked = vec![vec![false; m]; n]; for _ in 0..q { let mut ab = String::new(); std::io::stdin().read_line(&mut ab).ok(); let ab: Vec = ab.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let a = ab[0]-1; let b = ab[1]-1; checked[a][b] = true; } let mut dp = vec![vec![0usize; m+1]; n+1]; for i in 0..=n { for j in 0..=m { if i+1 <= n { dp[i+1][j] = dp[i+1][j].max(dp[i][j]); } if j+1 <= m { dp[i][j+1] = dp[i][j+1].max(dp[i][j]); } if i+1 <= n && j+1 <= m { dp[i+1][j+1] = dp[i+1][j+1].max(dp[i][j] + if checked[i][j] { 1 } else { 0 }); } } } println!("{}", dp[n][m]); }