Longest Common Prefix

Easy 20 XPStrings

Commonly asked at Amazon, Google, Adobe

Read a line of words and print the longest prefix that all of them share. If there is none, print -1.

Input
One line of space-separated lowercase words.
Output
The common prefix, or -1.

Sample 1

Input

flower flow flight

Output

fl

Sample 2

Input

dog racecar car

Output

-1

Read input with input() (no prompt message) and print only the answer. Run tries the Input box; Submit checks all test cases.

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.
The solution unlocks after 3 submissions.