# Harry potter array problem

QI. Harry Potter has an array a, consisting of n integers al , a2,…… an. The boy cannot sit and do nothing, he decided to study an array.
Harry Potter took a piece of paper and wrote out m integers l(1), l(2), …….,I(m) (1 <= I(i) n).
For each number I(i ) he wants to know how many distinct numbers are staying on the positions I(i), I(i + 1),…….,n. Formally, he want to find the number of distinct numbers among a[l(i)], a[l(i + 1)],…… a[n]. Harry Potter wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each I(i).

Input Format :

The first line contains two integers n and m (1 <= n, m 1000). The second line contains n integers al, a2……, an (1<= ai <= 100000) — the array elements.
Next m lines contain integers 1(1), 1(2),……. I(m). The i-th line contains integer l(i) (1 <= l(i) <= n).

Output Format

Print m lines — on the i-th line print the answer to the number I(i).

Sample input:

7 10

1 3 8 6 2 2 7

4 2 6 3 4 4 6 2 7 4

Sample output:

3
5
2
4
3
3
2
5
1
3

refer this link for the working code in O(n) complexity which will even work for n<=1000000.