SDE Path

Longest Common Prefix

Easy

Longest Common Prefix

Find the longest common prefix string among an array of strings.

Input format

The first line contains N. The second line contains N lowercase words separated by spaces.

Output format

Print the longest common prefix of all words, or -1 if there is none.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
3
flower flow flight
Expected output
fl
Example 2
Input
3
dog racecar car
Expected output
-1