a = int(input()) b = list(str(input())) b.reverse() mod = 10**9+7 N = 2*10**5 P = [0]*N P[0] = 1 for i in range(1,N): P[i] = P[i-1]*a P[i] %= mod s = 0 for i in range(len(b)): s += P[i]*int(b[i]) s %= mod ans = 0 for i in reversed(range(len(b))): if i == len(b)-1: ans += (s-P[i]+1)*i ans %= mod else: ans += (P[i+1]-P[i])*i ans %= mod print(ans)