E. Brass Birmingham: coins
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Today Igor and Ira together with friends  — Sasha and Lesha — are playing a new board game "Brass Birmingham".

In each round, the players take turns making moves. During the turn, the player can build one industry per city, a road connecting two cities, or perform an action. Players pay money for all their buildings in this game, as in the real world, everything costs money. At the end of his turn, the player builds a tower of spent coins and puts it next to his figure in the payment field, and at the end of the round, the spent coins are returned to the bank.

Igor wants to start the next round as soon as possible, so he decided to optimize the process of returning money to the bank. In one operation, he collects coins of the same nominal from all the tops of the towers. How often does Igor need to repeat this operation to start a new round as quickly as possible?

Input

The first string contains an integer $$$n$$$ $$$(1\leq n\leq 30)$$$ — the number of different coin nominals.

The second string contains four integers $$$m_i$$$ $$$(1\leq m_i\leq 30, 1\leq i\leq 4)$$$ — the number of coins in the tower of the $$$i$$$ player.

The next four strings contain a description of each player's towers. The $$$i$$$ th of them contains $$$m_i$$$ integers $$$k_{ij}$$$ $$$(1\leq k_{ij}\leq n,\; 1\leq i\leq 4,\; 1\leq j\leq m_i)$$$ — the nominal value of the coin with the number $$$j$$$. The coins are numbered from bottom to top.

Output

In a single string print the number — the minimum number of operations necessary for Igor to return all the coins to the bank.

Examples
Input
5
2 2 2 2
1 1
1 2
1 3
1 4
Output
4
Input
5
3 2 3 2
1 1 1
3 2
2 2 3
4 5
Output
6