def longest_common_prefix(strings):
    if not strings:
        return "Invalid input"
    strings.sort()
    
    first = strings[0]
    last = strings[-1]
    i = 0
    
    while i < len(first) and i < len(last) and first[i] == last[i]:
        i += 1
    
    prefix = first[:i]
    return prefix if prefix else "Invalid input
N = int(input())
words = input().split()

if len(words) != N:
    print("Invalid input")
else:
    print(longest_common_prefix(words))