In a word processor (such as Word, Hangul, or Notepad), when you print you can specify the page ranges to print by typing them directly. For example, you might type:
10-15,25-28,8-4,13-20,9,8-8
You list the ranges you want to print, separated by commas (,).
Each print range is either a single positive integer, or two positive integers separated by a hyphen (-). In a range made of two numbers, call the first number low and the second high. The rules are:
low > high, that range is not printed.Given the print ranges, write a program that counts how many distinct pages are actually printed.
The input consists of several test cases. For each test case, the first line contains the total number of pages in the document, and the second line contains the print ranges in the format described above. The last line of the input contains a single 0.
A document has at most 1000 pages, and the length of a print-range string does not exceed 1000 characters.
For each test case, print the number of distinct pages that are actually printed, one per line.