#K12751. Common Subsequence Existence

    ID: 23760 Type: Default 1000ms 256MiB

Common Subsequence Existence

Common Subsequence Existence

Given two sequences of integers, determine whether there exists a non-empty subsequence that is common to both sequences. In this problem, a common subsequence is defined as any sequence (not necessarily contiguous) that appears in both sequences. Practically, this problem reduces to checking if the two sequences have at least one common element.

The input begins with two integers n and m which represent the sizes of the first and second sequences respectively. The next line contains n space-separated integers comprising the first sequence, and the following line contains m space-separated integers comprising the second sequence.

Your task is to output "YES" if there exists at least one integer present in both sequences, and "NO" otherwise.

Note: Since the sequences can be large, an efficient solution is expected.

inputFormat

The first line contains two integers n and m (the lengths of the sequences). The second line contains n space-separated integers representing the first sequence. The third line contains m space-separated integers representing the second sequence.

outputFormat

Output a single line with "YES" if there exists at least one common element between the two sequences, otherwise output "NO".

## sample
3 4
1 2 3
4 5 2 6
YES

</p>