406014: GYM102218 G Generating Problems

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Generating Problemstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Abraham and Filiberto have been arguing a lot during the last two months. They haven't decided which problems are going to be used in the 11th edition of the Annual Programming Contest.

As the date of the competition is coming soon, they both prepared different problem sets and now they have several problems that can be used in this contest. Both of them labeled their problems by difficulty $$$d$$$ and have arrange them into 2 different arrays, proposing the order that the problems should have during the competition.

Abraham and Filiberto are both very foolish, they proposed the order of the problems and don't want to change it in any way. That means that if a problem $$$A$$$ appears before a problem $$$B$$$ in the original array proposal, then in the final problem set, $$$A$$$ has to appear before problem $$$B$$$.

After some time of discussing how to choose the problems for the competition, they agreed with the following deal:

  • They will choose the same quantity of problems from both proposals.
  • If a problem with difficulty $$$D$$$ is chosen from Abraham's array, then a problem with the same difficulty must be chosen from Filiberto's array.
  • Problems must be ordered by strictly increasing difficulty in the final problem set.
  • And the order of problems in the final problem set, has to preserve the original order in the arrays proposal.

They want to maximize the number of problems that can be used in this competition.

As they are very tired to solve this problem, they ask for your help to compute the answer.

Input

The first line contains two integer numbers $$$n$$$ and $$$m$$$ $$$(1 \le n,m \le 10^4)$$$ - size of Filiberto and Abraham's arrays proposal.

Second line contains $$$n$$$ integers $$$d_i$$$ $$$(1 \le d_i \le 10^9)$$$ - representing the difficulties of Filiberto's array proposal.

Next line contains $$$m$$$ integers $$$x_i$$$ $$$(1 \le x_i \le 10^9)$$$ - representing the difficulties of Abraham's array proposal.

Output

Print one integer - maximum number of problems that can be used in the competition.

ExampleInput
6 5
1 2 1 2 1 3
2 1 3 2 1
Output
4
Note

In the test case you can select 1st and 6th element from the first array and 2nd and 3rd from the second array.

The final problem set difficulties will look as: [1, 1, 3, 3].

Note that numbers marked as bold belong to Abraham's array proposal and they appear in the same order as in the original array.

加入题单

算法标签: