from itertools import permutations N = int(input()) A = list(map(int, input().split())) P = list(permutations(range(N), N)) x = float("inf") for p in P: x_i = 0 for i in p: x_i = 10*x_i + A[i] x = min(x_i, x) print(x%998244353)