Data Structure

Given M required cells in a triangular pyramid with N up to 1e9, find the minimum number of filled cells so that every filled cell has both supporting cells below it filled.

Hard8GreedySortingMathCombinatoricsNo attempts yetTime limit2sMemory limit512 MB

Problem

Inside a computer, every piece of data is stored in a two-dimensional pyramid of data blocks.

One such pyramid has NN rows, numbered 11 through NN from top to bottom. Row rr has rr block spaces, labelled (r,1)(r, 1) through (r,r)(r, r) from left to right. Every block space (r,c)(r, c) in rows 11 through N1N - 1 rests on two supporting block spaces in the row below it, namely (r+1,c)(r + 1, c) and (r+1,c+1)(r + 1, c + 1). The picture below shows a pyramid with 6 rows, with the block spaces (3,1)(3, 1), (4,4)(4, 4) and (6,2)(6, 2) marked in red.

Each block space either contains data or is empty. A block space that contains data is stable only if it is in the bottom row (row NN), or if both of its two supporting block spaces also contain data. The whole pyramid is stable only if all of its non-empty block spaces are stable.

There are MM block spaces that must contain data, and the ii-th of them is block space (ri,ci)(r_i, c_i). Every other block space of the pyramid may be filled with arbitrary data or be left empty. Data is expensive, so you want the smallest possible amount of it. Find the smallest number of block spaces that can contain data while all MM required block spaces contain data and the entire pyramid is stable.

Input

The first line contains two integers NN and MM (1N1091 \le N \le 10^9, 1M1051 \le M \le 10^5).

Each of the next MM lines contains two integers rir_i and cic_i (1ciriN1 \le c_i \le r_i \le N), the row and the position within that row of the ii-th required block space. The MM required block spaces are distinct.

Output

Print one integer, the smallest number of block spaces that can contain data such that the entire pyramid is stable. This value may not fit in a 32-bit signed integer.