QOJ.ac

QOJ

时间限制: 2 s 内存限制: 128 MB 总分: 100

#6358. Sequence

统计

For Jia Yuan's birthday, her friend bought her an interesting toy. The toy features a sequence of numbers, and the values of some elements in the sequence may change, but at any given moment, at most one value changes.

Jia Yuan has already determined all possible changes. She wants to ask you: can you select a subsequence such that it remains non-decreasing under any of the possible changes? Please tell her the maximum length of such a subsequence.

Note: In each change, at most one value changes.

In Sample 1, all possible changes are: 1 2 3 2 2 3 1 3 3 1 1 3 1 2 4 Choosing the entire original sequence as the subsequence ensures it remains non-decreasing under any change.

In Sample 2, all possible changes are: 3 3 3 3 2 3 Choosing the first and third elements, or the second and third elements, satisfies the requirement.

Input

The first line contains two positive integers $n$ and $m$, representing the length of the sequence and the number of possible changes, respectively. The next line contains $n$ integers, representing the initial state of the sequence. The next $m$ lines each contain two integers $x$ and $y$, indicating that the $x$-th element of the sequence can change to the value $y$. $1 \le x \le n$

Output

Output a single integer representing the answer.

Constraints

  • For 20% of the data, all numbers are $\le 300$.
  • For 50% of the data, all numbers are $\le 3,000$.
  • For 100% of the data, all numbers are positive integers and $\le 100,000$.

Examples

Input 1

3 4
1 2 3
1 2
2 3
2 1
3 4

Output 1

3

Input 2

3 1
3 3 3
2 2

Output 2

2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.