Boxes

Every Junior Balkan Olympiad in Informatics ends with the traditional Closing ceremony - a ceremony where the best contestants get medals for their achievements. This year is no different - after the completion of both competition days, the organizers of JBOI 2012 will give medals to the best contestants at a special ceremony held in Skopje.

In order to be as original as possible, Mile - one of the organizers of JBOI 2012, proposed a great idea: in addition to giving each contestant a medal, each of the medal winners will receive a special colored box in the shape of a cube to put the medal in.

However, after the organizers received the medal boxes from the local shop, Mile discovered that not all boxes are colored the same. Now, your job is to help the shop calculate the minimum number of faces that must be recolored in order to make all medal boxes look the same (or Mile won't pay the shop for the boxes). Two boxes look the same if, after they are rotated arbitrarily, they have the same colors on their corresponding faces. In other words, two boxes look the same if and only if you can rotate the two boxes so that the color on the front face of the first box matches the color on the front face of the second box, the color on the left face of the first box matches the color on the left face of the second box, etc.



Input

The first line of input contains the integer N (2 ≤ N ≤ 100) - the number of medal boxes. Each of the following N lines contains 6 integers Fi1, Fi2, Fi3, Fi4, Fi5 and Fi6 (0 ≤ Fi1, Fi2, Fi3, Fi4, Fi5, Fi6 ≤ 6) - the color that each of the 6 faces of the i-th medal box was originally colored with. The 6 integers describing the colors are given in the following order: front (Fi1), top (Fi2), back (Fi3), bottom (Fi4), left (Fi5) and right face of the box (Fi6).

In test cases worth at least 20% of the full score, the optimal solution will be to color all faces of all boxes with the same color.



Output

Your program should output the minimum number of faces that must be recolored in order to make all medal boxes look the same.



Constraints

Time limit: 1 second
Memory limit: 64 megabytes



Examples


input
2
3 1 4 2 5 6
5 1 6 2 4 3
output
0


input
7
1 5 2 5 1 0
5 1 6 0 4 4
5 1 2 5 5 4
4 3 6 1 3 4
4 5 0 0 5 1
5 3 4 3 4 1
3 4 5 5 1 4


output
16


Explanation for test example 1: The two medal boxes look the same (the second box is the same as the first one but rotated once to the right).



 Submit your code