mod = int(1e9 + 7) a = int(input()) b = int(input()) x = 0 for v in str(b): x *= a x += int(v) i = a res = 0 while i <= x: res += x - i + 1 res %= mod i *= a print(res)