Eustace-Alex
After a brilliantly perfomed operation Stirlitz is able to determine the strength of the fascist army. Naturally this information is waited in the headquarters of the Soviet army for already four years. To communicate with the staff Stirlitz uses n wireless operators. Each radio operator must pass a message from Shtirlits to headquarters. Stirlitz as a cunning spy, encrypt the message this way: for each radio operator he give the same number - the size of the army in their number system in such a way that all the number system bases at wireless operators are pairwise coprime. After the transfer of radiograms Mueller bloodhounds were able to identify the last character of each message. You work full-time programmer and need to determine the minimum number that can be send by Stirlitz in his message. Mueller does not like binary code, so he wants you to print the desired number in the decimal notation.
Input
The first line contains number n - the number of radio operators Shtirlits has. The next line contains n numbers a_i - the base number system, which gave the message Stirlitz radio operators (2 ≤ a_i ≤ 36 ). In the third line of space-separated n symbols c_i - the last letter of each of the messages (0 ≤ c_i < a_i; c_i - any number from 0 to 9 or letter A through Z).
Output
Print the minimum number that can transfer Stirlitz in the decimal system.