mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline a = int(input()) B = input().rstrip('\n') B = list(map(int, B)) bb = 0 for i in range(len(B)): bb = (bb + B[-i-1] * (pow(a, i, mod))%mod)%mod ans = 0 for i in range(len(B)): if i == len(B) - 1: ans = (ans + i * (bb - pow(a, i, mod) + 1))%mod else: ans = (ans + i * (a-1) * pow(a, i, mod))%mod print(ans) if __name__ == '__main__': main()