Citation Format

Time Limit : 1 sec, Memory Limit : 65536 KB
Japanese version is here

Problem A: Citation Format

To write a research paper, you should definitely follow the structured format. This format, in many cases, is strictly defined, and students who try to write their papers have a hard time with it.

One of such formats is related to citations. If you refer several pages of a material, you should enumerate their page numbers in ascending order. However, enumerating many page numbers waste space, so you should use the following abbreviated notation:

When you refer all pages between page a and page b (a < b), you must use the notation "a-b". For example, when you refer pages 1, 2, 3, 4, you must write "1-4" not "1 2 3 4". You must not write, for example, "1-2 3-4", "1-3 4", "1-3 2-4" and so on. When you refer one page and do not refer the previous and the next page of that page, you can write just the number of that page, but you must follow the notation when you refer successive pages (more than or equal to 2). Typically, commas are used to separate page numbers, in this problem we use space to separate the page numbers.

You, a kind senior, decided to write a program which generates the abbreviated notation for your junior who struggle with the citation.


Input consists of several datasets.

The first line of the dataset indicates the number of pages n.

Next line consists of n integers. These integers are arranged in ascending order and they are differ from each other.

Input ends when n = 0.


For each dataset, output the abbreviated notation in a line. Your program should not print extra space. Especially, be careful about the space at the end of line.


  • 1 ≤ n ≤ 50

Sample Input

1 2 3 5 6
7 8 9

Output for the Sample Input

1-3 5-6

Source: University of Aizu Programming Contest , Aizu-Wakamatsu, Japan, 2010-05-29
Problem Setter:  Takashi Tayama