Samtris

Given N marked cells in a 7-column grid, find the fewest 3x1 bars (vertical or horizontal) that can be dropped so all marked cells end up covered.

Hard8Dynamic programmingGreedyImplementationBrute forceNo attempts yetTime limit5sMemory limit128 MB

Problem

Samtris is a game less popular than Tetris. Only bars of size 3×13 \times 1 appear in it, and the screen is 7 columns wide. A bar appears at the top of the screen and comes down, and you may rotate it before it lands. A bar placed vertically takes three cells stacked in one column, and a bar placed horizontally takes three neighboring columns in one row. A bar stops as soon as the cell right below it is the floor or a cell that already holds another bar. A horizontal bar stops when even one of its three cells is blocked, so empty cells that can never be filled are sometimes left under it. A row that becomes full is never cleared.

The goal is different from Tetris. The game ends once all NN cells marked on the screen are filled by bars. Cells that are not marked may be filled as well. Find the smallest number of bars needed to end the game.

The picture below shows the first example.

Input

The first line contains the number of marked cells NN. (1N2001 \le N \le 200)

Each of the next NN lines contains the column number and the row number of one marked cell, in that order. The column number is an integer between 11 and 77, and the row number is an integer between 11 and 10810^8. The bottom row of the screen has row number 11.

Output

Print the smallest number of bars.