## DMOPC '19 Contest 1 P5 - Broken String

View as PDF

Points: 17
Time limit: 1.4s
Memory limit: 128M

Author:
Problem type

During class, Bob's teacher wanted to try an interesting activity. He began by writing down a string of length containing only lowercase English letters, where is the number of students. Afterwards, he writes down each of the substrings of length , and gives one to each student. Bob and the rest of the class now need to find out what the original string could have been, or if the teacher has made a mistake.

#### Constraints

You only need to determine whether or not the teacher has made a mistake.
If there is a candidate for the original string, print out any string of length .

#### Input Specification

The first line contains two space-separated integers, and .
lines follow, each containing a string of length , one of the strings that the students received.

#### Output Specification

On one line, output any string that the teacher could have written down. If there are multiple such strings, then output any of them.
If there are no candidates for the original string, output -1.

#### Sample Input 1

5 3
obl
rob
lem
pro
ble

#### Sample Output 1

problem

#### Sample Input 2

2 5
abcde
cdefa

#### Sample Output 2

-1