#P3395. B's Escape from Blockades

    ID: 16651 Type: Default 1000ms 256MiB

B's Escape from Blockades

B's Escape from Blockades

B stands on an \(n\times n\) chessboard at the starting cell \((1,1)\) and needs to reach \((n,n)\). Each second, he can move one step in one of the four cardinal directions (up, down, left, or right). However, at the end of every second, C places a permanent blockade at a predetermined cell \((x,y)\). B knows the complete schedule of these blockades and must plan a route such that he is never on a cell at the moment it becomes blocked.

More formally, let the schedule be given for \(T\) seconds. At time \(0\), B is at \((1,1)\) and no cells are blocked. For each second \(i\) (\(1\le i\le T\)), B makes one move to an adjacent cell. Then, at the end of that second, a blockade is placed at cell \((x_i,y_i)\). Note that the blockade introduced at second \(i\) remains permanently on the board. Thus, when B moves at the \(i\)th second, his destination cell must not have been blocked by any of the previous \(i-1\) blockades and must not be the cell at which the blockade will be placed at the end of the current second. If B reaches \((n,n)\) in less than \(T\) seconds, subsequent blockades do not affect him.

Your task is to determine if B can reach \((n,n)\) safely given the schedule of blockade placements.

inputFormat

The first line contains two integers \(n\) and \(T\) \(\bigl(1\le n\le 1000,\, 0\le T\le 10^4\bigr)\), representing the size of the board and the number of seconds (blockade placements), respectively.

If \(T>0\), each of the following \(T\) lines contains two integers \(x\) and \(y\) \(\bigl(1\le x,y\le n\bigr)\), indicating that at the end of that second a blockade will be placed at cell \((x,y)\).

outputFormat

Print a single line: output YES if there exists a sequence of moves for B to safely reach \((n,n)\); otherwise, output NO.

sample

3 4
2 2
1 3
2 3
3 2
YES