A=int(input()) B=input() mod=10**9+7 N=len(B) ANS=0 X=A-1 for i in range(N-1): ANS+=X*i X=X*A%mod ANS%=mod C=int(B[0])-1 for i in range(1,N): C=(C*A+int(B[i]))%mod C+=1 print((ANS+C*(N-1))%mod)