import sys from math import gcd sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) N = I() C = [0]+LI() mod = 10**9+7 for i in range(1,10): if C[i] == N: ans = pow(10,N,mod)-1 ans %= mod ans *= pow(9,mod-2,mod) ans %= mod ans *= i ans %= mod print(ans) exit() a = 0 for i in range(1,10): if not C[i]: continue for j in range(i+1,10): if not C[j]: continue a = gcd(a,9*(j-i)) def matrix_multiplication_mod(A,B,p): l = len(A) m = len(B) n = len(B[0]) C = [[0]*n for _ in range(l)] for i in range(l): for j in range(n): C[i][j] = sum((A[i][k]*B[k][j]) % p for k in range(m)) % p return C def matrix_power_mod(A,n,p): l = len(A) C = [[0] * l for _ in range(l)] for i in range(l): C[i][i] = 1 while n > 0: if n % 2 == 1: C = matrix_multiplication_mod(C,A,p) A = matrix_multiplication_mod(A,A,p) n >>= 1 return C X = [[10,1],[0,1]] s = 0 r = 0 for i in range(1,10): c = C[i] b = matrix_power_mod(X,c,a)[0][1] s += i*b*pow(10,r,a) s %= a r += c ans = gcd(a,s) print(ans)