Modern Art#10523

Modern Art

1 second
128 megabytes
Medium

Art critics around the world have only recently begun to recognize the creative genius of the great bovine painter, Picowso.

Picowso paints in a very particular way. She starts with an n \times n blank canvas, represented by an n \times n grid of zeros, where a zero indicates an empty cell of the canvas. She then paints up to rectangles on the canvas, using one of colors, conveniently numbered from to . For example, she might start by painting a rectangle in color , producing the following intermediate canvas:

2220
2220
2220
0000

She might then paint a rectangle in color :

2220
2777
2777
0000

Finally, she might paint a small rectangle in color :

2230
2737
2777
0000

Each rectangle has sides parallel to the edges of the canvas. A rectangle can be as large as the entire canvas or as small as a single cell. Each color from to is used exactly once, although later colors may completely cover parts of earlier colors.

Given the final state of the canvas, count how many of the colors still visible in the final picture could have been painted first.

Input

The first line contains the size of the canvas n~(1 \le n \le 10). The next lines describe the final picture of the canvas. Each line contains integers, each in the range to . The input is guaranteed to have been produced by painting successive rectangles in different colors as described above.

Output

Print the number of colors that could have been painted first among all colors that are still visible in the final canvas.

Examples

In this example, only color could have been painted first. Color clearly had to be painted after color , and color clearly had to be painted after color .

Example 1

Loading
Loading