import sys readline=sys.stdin.readline from collections import defaultdict A=int(readline()) B=readline().rstrip()[::-1] mod=10**9+7 le=len(B) powA=[1] for i in range(1,le): powA.append(powA[-1]*A%mod) s=sum(int(b)*powA[i]%mod for i,b in enumerate(B)) ans=0 for i in range(1,le): ans+=s-(powA[i]-1) ans%=mod print(ans)