Time limit
2s
Memory limit
128 MB
Sejun has an R×C chessboard with N unusable empty squares. A rook cannot be placed on an unusable square, but such a square does not block attacks. Therefore, two rooks in the same row or the same column can attack each other even if unusable squares lie between them.
Find the maximum number of rooks that can be placed on the board so that no two rooks attack each other. A rook attacks another rook if they are in the same row or in the same column.
The first line contains the number of rows R, the number of columns C, and the number N of unusable empty squares. Each of the next N lines contains the coordinate of one unusable square. Coordinates are given as row and column. The top row is row 1, and the leftmost column is column 1.
R and C are positive integers at most 300, and N is a nonnegative integer at most 600.
Print the maximum number of rooks that can be placed so that no two rooks attack each other.