Power of time#10142

Power of time

1 second
128 megabytes
Easy

There are processes to be completed by you. All the processes have a unique number assigned to them from to . You are given two things:

If the process in the calling order cannot be executed (does not fit the ideal order), then it is put to the end of the calling order queue for execution.

Now, let us demonstrate this by an example. Let's say that there are processes, the calling order of the processes is: - - . The ideal order is: - - , i.e. process number will only be executed after process number has been completed; process number will only be executed after process number has been executed.

Total time taken: units.

Executing a process takes unit of time. Changing the position takes unit of time.

Input

First line contains the number of processes (1 \le n \le 100). Second line contains the calling order of the processes. The third line contains the ideal order of the processes.

Output

Print the total time taken for the entire queue of processes to be executed.

Examples

Example 1

Loading
Loading