import math N = int(input()) c = [0] + list(map(int,input().split())) for i in range(10): if c[i] == N: ans = pow(10,N,mod)-1 ans *= pow(9,mod-2,mod) ans %= mod ans *= i ans %= mod print(ans) exit() x = 0 for i in range(10): x += (c[i]%9)*i x %= 9 if x == 3 or x == 6: ans = 3 elif x == 0: ans = 9 else: ans = 1 g = 0 for i in range(10): for j in range(10): if i != j and c[i] >= 1 and c[j] >= 1: t = i-j while t%3 == 0: t //= 3 g = math.gcd(g,t) ans *= g print(ans)