This page is still under construction.

Parts of this page are still being built. What you see may change.

Non-Attacking Knights

Time limit1sMemory limit128 MB

Summary
Place the most knights on a board with blocked squares so no two attack each other.
Level

Medium7 of 10

Topics
Graph, BFS, DFS
Solved
No attempts yet

Problem

You are given an n×nn \times n chessboard from which some squares have been removed. Determine the maximum number of chess knights that can be placed on the remaining squares so that no two knights attack each other.

Figure 1: a knight placed on square S attacks the squares marked with x.

Write a program that:

  • reads the description of the board together with its removed squares from standard input,
  • computes the maximum number of mutually non-attacking knights that can be placed on the board,
  • writes the result to standard output.

Input

The first line contains two integers nn and mm, where 1≤n≤2001 \le n \le 200 and 0≤m≤n20 \le m \le n^2. Here nn is the size of the board and mm is the number of removed squares.

Each of the next mm lines contains a pair of integers xx and yy (1≤x,y≤n1 \le x, y \le n) separated by a single space, giving the coordinates of a removed square. The top-left corner of the board has coordinates (1,1)(1, 1) and the bottom-right corner has coordinates (n,n)(n, n). No square is listed more than once.

Output

Print exactly one line containing a single integer: the maximum number of mutually non-attacking knights that can be placed on the given board.

Examples1

  1. Example 1

    Input
    3 2
    1 1
    3 3
    
    Expected output
    5