Fake Tickets

Interview

Time limit1sMemory limit128 MB

Summary
Given N genuine ticket numbers and a list of M collected ticket numbers, count how many distinct values appear more than once in the list.
Level

Easy3 of 10

Topics
Array, Hash map, Implementation
Solved
No attempts yet

Problem

Your school threw a big party to celebrate your team's win in the prestigious, world-famous ICPC (International Collegiate Poetry Contest). Everyone at school was invited to an evening of cocktails, dinner, and a reading of your team's work to the audience. The evening was a great success — far more people than you expected showed interest in your poetry — although some of your critics said it was the food, not the words, that drew such a crowd.

Whatever the reason, the next day you learned why the school hall had felt so full: the director confided that several of the tickets guests had used were fake. The genuine tickets were numbered sequentially from 11 to NN (N≤10000N \le 10000). The director suspects some guests used the scanner and printer in the Computer Room to copy real tickets. He hands you the pack of all tickets collected at the entrance and asks you to determine how many sequence numbers were duplicated — that is, how many numbers appear on more than one ticket in the pack.

Input

The input contains data for several test cases. Each test case consists of two lines. The first line has two integers NN and MM, the number of genuine tickets and the number of guests attending the party, respectively (1≤N≤100001 \le N \le 10000 and 1≤M≤200001 \le M \le 20000). The second line has MM integers TiT_i, the ticket numbers in the pack (1≤Ti≤N1 \le T_i \le N). The end of input is indicated by a line with N=M=0N = M = 0, which must not be processed.

Output

For each test case, print a single line containing the number of distinct sequence numbers that appear on more than one ticket in the pack.

Examples3

  1. Example 1

    Input
    5 5
    3 3 1 2 4
    6 10
    6 1 3 6 6 4 2 3 1 2
    0 0
    
    Expected output
    1
    4
    
  2. Example 2

    Input
    5 5
    1 2 3 4 5
    0 0
    
    Expected output
    0
    
  3. Example 3

    Input
    3 4
    2 2 2 2
    0 0
    
    Expected output
    1