#P1820. Waiting Tiles in Simplified Mahjong

    ID: 15103 Type: Default 1000ms 256MiB

Waiting Tiles in Simplified Mahjong

Waiting Tiles in Simplified Mahjong

In this problem, there is a special set of Mahjong tiles numbered from \(1\) to \(n\) where there are infinitely many copies of each tile. A pair (雀头) is defined as two identical tiles (e.g. \(2,2\) or \(7,7\)). A set (面子) can be either a triplet (刻子), which is three identical tiles (e.g. \(1,1,1\) or \(4,4,4\)), or a sequence (顺子), which consists of three consecutive numbered tiles (e.g. \(1,2,3\) or \(9,10,11\); note that \(1\) and \(n\) are not consecutive).

A hand is "winning" (和牌) if you can partition all the tiles into exactly one pair and some number (possibly zero) of sets. More precisely, if your hand (with an extra drawn tile added) can be partitioned as:

[ \text{Hand} = \text{pair} + \underbrace{\text{set} + \text{set} + \cdots + \text{set}}_{m\text{ sets}} ]

Note that the total number of tiles must be \(2+3m\) for some nonnegative integer \(m\). A hand drawn by small A consists of \(k\) tiles. A tile \(x\) (\(1 \le x \le n\)) is called a "waiting tile" (听) if by adding one tile \(x\) to the hand, the new hand can be partitioned into one pair and several sets (i.e. it becomes a winning hand).

Your task is: given \(n\), \(k\), and a list of \(k\) drawn tiles, determine all waiting tiles. If there is no waiting tile, output -1.

inputFormat

The first line contains two integers \(n\) and \(k\) (\(1 \le n \le 100\), \(1 \le k \le 100\)). The second line contains \(k\) integers, representing the drawn tiles. It is guaranteed that after adding the candidate tile, the total number of tiles is \(2+3m\) for some nonnegative integer \(m\) if that tile is a waiting tile.

Note: The tiles are numbers between \(1\) and \(n\), inclusive.

outputFormat

If there are waiting tiles, print them in increasing order separated by a single space. Otherwise, print -1.

sample

7 13
1 1 1 2 2 2 3 3 3 4 5 6 7
1 2 3 4 7