#K71327. Common Collection Strings

    ID: 33507 Type: Default 1000ms 256MiB

Common Collection Strings

Common Collection Strings

You are given two collections of strings, one from Taro and one from Jiro. Your task is to find all the strings that are present in both collections and output them in lexicographical order.

If there is no common string between the two collections, print -1.

Note: The lexicographical order is determined by the usual string comparison rules. All input strings consist of lowercase English letters.

Input Format: The first line contains two integers n and m, representing the number of strings in Taro's and Jiro's collections respectively. The second line contains n space-separated strings. The third line contains m space-separated strings.

Output Format: If there are common strings, print them in a single line separated by spaces in lexicographical order. Otherwise, print -1.

inputFormat

The input consists of three lines:

  • The first line contains two integers, n and m, representing the number of strings in Taro's and Jiro's collections respectively.
  • The second line contains n space-separated strings (Taro's list).
  • The third line contains m space-separated strings (Jiro's list).

outputFormat

If there is at least one common string, output them in lexicographical order separated by a single space; otherwise, print -1.

## sample
3 4
apple banana orange
apple grape banana kiwi
apple banana