#!python3
def main():
	freq = [[0 for _ in range(26)] for _ in range(26)]
	n = int(input())
	for _ in range(n):
		s = input()
		for i in range(len(s)-1):
			freq[ord(s[i]) - ord('a')][ord(s[i + 1]) - ord('a')] += 1

	ans = 1
	k = len(s)
	for i in range(k):
		j = i + 1
		while j < k and freq[ord(s[j - 1]) - ord('a')][ord(s[j]) - ord('a')] == n:
			j += 1

		ans = max(ans, j - i)

	print(ans)

if __name__ == "__main__":
	main()
