Problem:
Loading

Aizu Ocean Transport Company (AOTC) accepted a new shipping order. The pieces of the cargo included in this order all have the same square footprint (2m x 2m). The cargo room has a rectangular storage space of 4m width with various longitudinal extents. Each pieces of cargo must be placed in alignment with partition boundaries which form a 1m x 1m square grid. A straddling arrangement with a neighboring partition (for example, protrusion by 50 cm) is not allowed. Neither an angled layout nor stacked placement are allowed. Note also that there may be some partitions on which any cargo loading is prohibited.

AOTC wishes to use the currently available ship for this consignment and needs to know how many pieces of cargo it can accommodate.

Make a program to report the maximum cargo capacity of the cargo space given the following information: the depth (m) of the cargo space and the loading-inhibited partitions.

Input

The input is given in the following format.

H N
x_1 y_1
x_2 y_2
:
x_N y_N

The first line provides the longitudinal depth H (2 ≤ H ≤ 104) of the cargo space in meters and the number of load-inhibited partitions N (0 ≤ N ≤ 4 × 104). Each of the subsequent N lines defines the position of the i-th load-inhibited partition x_i (0 ≤ x_i ≤ 3) and y_i (0 ≤ y_i ≤ H-1) in integers, where x = 0 and y = 0 indicate the bottom-left corner partition. A load-inhibited partition appears only once in the list.

Output

Output the maximum number of cargo pieces loaded into the cargo space.

Sample Input 1

5 3
0 1
1 2
3 3

Sample Output 1

2

Input example 1 corresponds to the cargo layout shown in the left-most figure.

Sample Input 2

6 4
0 2
1 3
3 4
0 5

Sample Output 2

4

Solution in C# (judge verdict: Wrong Answer)

using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var n = int.Parse(line[1]);
        var map = new int[4, h];
        for (int i = 0; i < n; i++)
        {
            string[] line2 = Console.ReadLine().Trim().Split(' ');
            map[int.Parse(line2[0]), int.Parse(line2[1])] = 1;
        }
        var yL = 0;
        var acount = 0;
        while (yL < h)
        {
            var a = ChkBag(map, yL);
            acount += a;
            yL += 1;
        }
        Console.WriteLine(acount);
    }
    public static int ChkBag(int[,] m, int yL)
    {
        var acount = 0;
        if (yL + 2 > m.GetLength(1)) return 0;
        if (m[0, yL] == 0 && m[1, yL] == 0 && m[0, yL + 1] == 0 && m[1, yL + 1] == 0)
        {
            acount++;
            m[0, yL] = 1; m[1, yL] = 0; m[0, yL + 1] = 0; m[1, yL + 1] = 0;
            if (m[2, yL] == 0 && m[3, yL] == 0 && m[2, yL + 1] == 0 && m[3, yL + 1] == 0)
            {
                m[2, yL] = 1; m[3, yL] = 1; m[2, yL + 1] = 1; m[3, yL + 1] = 1;
                acount++;
            }
        }
        else
            if (m[1, yL] == 0 && m[2, yL] == 0 && m[1, yL + 1] == 0 && m[2, yL + 1] == 0)
        {
            m[1, yL] = 1; m[2, yL] = 1; m[1, yL + 1] = 1; m[2, yL + 1] = 1;
            acount++;
        }
        else if (m[2, yL] == 0 && m[3, yL] == 0 && m[2, yL + 1] == 0 && m[3, yL + 1] == 0)
        {
            m[2, yL] = 1; m[3, yL] = 1; m[2, yL + 1] = 1; m[3, yL + 1] = 1;
            acount++;
        }
        return acount;
    }
}