A = int(input())
B = input()
DB = int(B,A)
m = len(B)
AA = 1
mod = 10 ** 9 + 7
ans = 0
pre = A
i = 0
for i in range(1,m-1):
    now = pre * A
    now %= mod
    ans += (now - pre) * i
    ans %= mod
    pre = now
if DB >= pre:
    ans += (DB - pre + 1) * (i + 1)
    ans %= mod
print(ans)