#P6559. Lit Lights in the Town Grid

    ID: 19771 Type: Default 1000ms 256MiB

Lit Lights in the Town Grid

Lit Lights in the Town Grid

The town can be represented as an \( n \times n \) grid, with \( k \) cells containing houses. There are lights installed between every pair of adjacent cells (where adjacent means sharing a common edge). If two houses are adjacent, the light between them turns on. Your task is to determine the total number of lights that are turned on.

Note: Two cells are considered adjacent if they share a common side.

inputFormat

The first line contains two integers \( n \) and \( k \), representing the size of the grid and the number of houses respectively. Each of the following \( k \) lines contains two integers \( r \) and \( c \) (1-based indices) indicating the row and column of a house.

outputFormat

Output a single integer representing the total number of lights that are turned on.

sample

3 2
1 1
1 2
1