eolymp
bolt
Try our new interface for solving problems
Problems

Vinnis’ Friends

Vinnis’ Friends

Vinni Puh decided to play with his friends to one interesting game. Vinni took stone and decomposed them to a row to \textbf{M} heaps. Each of Vinnis’ friends approached and took the left heap of stones and placed all stones of this heap to all another heaps by one stone. If the quantity of the heaps of stones less than quantity of stones in the heap which took friend, then stones which remained form a new heap. It continues until the last Vinnis’ friend does not do his step. On the field remains N heaps of stone after the finish of game. Consider the example of the game: Initial state 7 5 1 3 6 Friend #1 6 2 4 7 1 1 1 Friend #2 3 5 8 2 2 2 Friend #3 6 9 3 2 2 Your task is, if you know the initial location of stones on heaps and eventual state you have to define the quantity of Vinnis’ friends. \InputFile There are two numbers in the first line -- \textbf{M} and \textbf{N} (\textbf{2} ≤ \textbf{M}, \textbf{N} ≤ \textbf{1000}), \textbf{M} is a quantity of the heaps of stones in the initial state, \textbf{N} is a quantity of heaps of stone after the finish of game. There are \textbf{M} integers (initial state) in the second line, \textbf{Mi} is a quantity of stones in a heap with number \textbf{і} (\textbf{1} ≤ \textbf{Mi} ≤ \textbf{100}). There are \textbf{N} integers (\textbf{1} ≤ \textbf{N}, \textbf{i} ≤ \textbf{100}) in the third line accordingly. \OutputFile You have to write down one number - quantity of Vinnis’ friends.
Time limit 1 second
Memory limit 64 MiB
Input example #1
6 5
7 4 3 2 1 9
5 13 4 3 1
Output example #1
4