|시간 제한||메모리 제한||제출||정답||맞힌 사람||정답 비율|
|1 초||128 MB||1||1||1||100.000%|
A rack in a police department consists of shelves that are organised in C columns and R rows.
To reach an object from any shelf, a ladder must be used. A ladder can be leaned against one column of shelves only. By climbing the ladder to a certain height (row) it is possible to take any object from that column up to climbed height including any object from adjacent (left and right) columns.
Policemen need to take certain objects from the rack. To lower a risk of injury at work, it is necessary to find a way to take all needed objects from the rack so that total height of all climbing is minimal possible. Total height is a sum of heights of all climbings.
A rack with some object lying on its shelves is given.
Write a program that will determine minimal possible total height of climbings needed to collect all the objects from the rack.
The first line of input file contains two integers C and R, 1 ≤ C ≤ 100, 1 ≤ R ≤ 100, number of columns and number of rows, separated by a space character.
The second line of input file contains an integer N, 1 ≤ N ≤ 100, number of shelves that needs to be reached.
Every of next N lines contains two integers A and B, 1 ≤ A ≤ C, 1 ≤ B ≤ R, separated by a space character, number of column and a row of a shelf that need to be reached.
The first and only line of output file should contain minimal possible total height of climbings needed to reach all given shelves.
5 5 3 2 3 3 4 4 4
6 20 4 5 6 1 1 6 1 3 7
10 10 5 9 1 7 6 5 8 4 1 3 2