#C931. Minimum Rooms Visited

    ID: 53389 Type: Default 1000ms 256MiB

Minimum Rooms Visited

Minimum Rooms Visited

The museum consists of n rooms and is monitored by m cameras. Each camera is placed in a specific room, as given by the list of camera rooms. When an intruder moves through the museum, the cameras record the intruder’s presence along with a timestamp. However, the same room may be recorded multiple times if multiple cameras in that room are triggered or if the same camera logs multiple events.

Your task is to determine the minimum number of distinct rooms the intruder could have visited based on the camera log entries. Note that each log entry contains two numbers: a timestamp and a camera ID. The camera ID corresponds to a room in the camera room list (using 1-indexing).

Input and Output Format

You will read input from stdin and write the result to stdout. See the input and output description for details.

inputFormat

The first line contains two integers n and m, representing the number of rooms and the number of cameras, respectively.

The second line contains m integers, where the i-th integer represents the room monitored by camera i (1-indexed).

The third line contains an integer k, the number of log entries.

This is followed by k lines, each containing two integers: a timestamp and a camera ID.

outputFormat

Output a single integer representing the minimum number of distinct rooms the intruder has visited.

## sample
5 3
1 3 5
5
1 1
2 2
3 3
4 1
5 2
3