import pprint


n = int(input())
s = [input() for _ in range(n)]

inf = 1 << 60


count = [[0 for _ in range(10)] for _ in range(10)]
for i in range(n):
    for j in range(10):
        k = int(s[i][j])
        count[k][j] += 1


ans = inf
for k in range(10):
    c = 0
    for j in range(10):
        c = max(c, 10 * (count[k][j] - 1) + j)
    ans = min(ans, c)


print(ans)
