MOD = 10**9+7 a = int(input()) b = input() n = len(b) ans = 0 r = 1 for i in range(n-1): ans += i*r*(a-1)%MOD r = r*a%MOD v = 0 for i in map(int,b): v = (v*a+i)%MOD ans += (n-1)*(v-r+1) print(ans%MOD)