MOD = 10**9+7 A = int(input()) B = list(map(int,list(input())))[::-1] K = len(B) ans = 0 for k in range(K-1): ans = (ans+k*(A-1)*pow(A,k,MOD))%MOD ans = (ans+(K-1)*(B[K-1]-1)*pow(A,K-1,MOD))%MOD cnt = 0 for k in range(K-1): cnt = (cnt+B[k]*pow(A,k,MOD))%MOD cnt += 1 ans = (ans+(K-1)*cnt)%MOD print(ans)