#abc185e. [abc185_e]Sequence Matching
[abc185_e]Sequence Matching
Problem Statement
We have an integer sequence of length and an integer sequence of length .
Takahashi will make a new sequence by removing some elements (possibly zero or all) from and concatenating the remaining elements.
Similarly, he will make another new sequence by removing some elements (possibly zero or all) from and concatenating the remaining elements.
Here, he will remove elements so that . ( denotes the length of for a sequence .)
Let be the total number of elements removed from and , and be the number of integers such that and . Print the minimium possible value of .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$A_1 \\hspace{7pt} A_2 \\hspace{7pt} A_3 \\hspace{5pt} \\dots \\hspace{5pt} A_N$ $B_1 \\hspace{7pt} B_2 \\hspace{7pt} B_3 \\hspace{5pt} \\dots \\hspace{5pt} B_M$
Output
Print the minimum possible value of .
Sample Input 1
4 3
1 2 1 3
1 3 1
Sample Output 1
2
If we make by removing from , and by removing nothing from , will be .
Here, there is just one integer such that and : , so will be , and will be , which is the minimum possible value.
Sample Input 2
4 6
1 3 2 4
1 5 2 6 4 3
Sample Output 2
3
If we remove nothing from and remove from , we have , and , which is the minimum possible value.
Sample Input 3
5 5
1 1 1 1 1
2 2 2 2 2
Sample Output 3
5
It is allowed to remove nothing from both and .