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 queries = (0..q).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); (temp[0]-1, temp[1]-1) }) .collect::>(); let mut checked = vec![vec![0usize; m]; n]; let mut dp = vec![vec![0usize; m+1]; n+1]; for &(a, b) in queries.iter() { checked[a][b] = 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] + checked[i][j]); } } } println!("{}", dp[n][m]); }