403198: GYM101064 E A Word to Trump All

Memory Limit:512 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. A Word to Trump Alltime limit per test2.5 smemory limit per test512 megabytesinputstandard inputoutputstandard output

Donald Trump is a terrible person. It is said he won't sleep at night until he has unfairly offended someone. Donald knows N horrible words and M kind words. For his next speech, he wants to compress the horrible words together to create the most offensive word of all time, while not saying any kind words.

We say a word s contains a word t if it has the word t as a contiguous substring. Trump wants to find the smallest word that contais all N horrible words he knows, and none of the M kind words. Determine one such word.

Input

On the first two integers N and M. In each of the next N lines, a horrible word. In each of the next M lines, a kind word.

Limits

  • 1 ≤ N + M ≤ 15
  • N ≥ 1, M ≥ 0
  • Each word is a string with at least 1 and at most 300 characters
  • All strings consist of lowercase characters from a to j
  • The sum of lengths of all strings will not exceed 300
Output

If there is no such word, print only "-" in a single line. Otherwise, print a single string, an answer to the problem. It can only contain lowercase characters from a to j. If there are multiple possible strings, print any of them.

ExamplesInput
3 0
hejja
gecab
jag
Output
hejjagecab
Input
3 1
ababab
bababb
abbb
babbb
Output
abbbabababb

Source/Category

加入题单

算法标签: