Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets 11311 (475 = 1·16^2 + 13·16^1 + 11·16^0). Alexander lived calmly until he tried to convert the number back to the decimal number system.

Alexander remembers that he worked with little numbers so he asks to find the minimum decimal number so that by converting it to the system with the base n he will get the number k.


-----Input-----

The first line contains the integer n (2 ≤ n ≤ 10^9). The second line contains the integer k (0 ≤ k < 10^60), it is guaranteed that the number k contains no more than 60 symbols. All digits in the second line are strictly less than n.

Alexander guarantees that the answer exists and does not exceed 10^18.

The number k doesn't contain leading zeros.


-----Output-----

Print the number x (0 ≤ x ≤ 10^18) — the answer to the problem.


-----Examples-----
Input
13
12

Output
12
Input
16
11311

Output
475
Input
20
999

Output
3789
Input
17
2016

Output
594


-----Note-----

In the first example 12 could be obtained by converting two numbers to the system with base 13: 12 = 12·13^0 or 15 = 1·13^1 + 2·13^0.

Difficulty: interview

Starter code:

Solutions:
n=int(input())
s=input()
pw=[1]
last=1
for i in range(70):
    if (last>1e19):
        break
    pw.append(last*n)
    last=last*n
dp=[1e19]*100
for i in range(100):
    dp[i]=[1e19]*100
dp[len(s)][0]=0
for i in range(len(s),-1,-1):
    for power in range(0,len(pw)):
        cur=''
        for j in range(i-1,-1,-1):
            cur=s[j]+cur
            if (int(cur)>n or int(cur)*pw[power]>1e19):
                break;
            if ((cur[0]!='0' or len(cur)==1) and int(cur)<n):
                dp[j][power+1]=min(dp[j][power+1],dp[i][power]+int(cur)*pw[power])
print(min(dp[0]))

n = int(input())
K = input()
m = len(K)

inf = 10 ** 100

dp = [inf] * (m + 1)
dp[0] = 0

for i in range(m):
	if K[i] == '0':
		dp[i + 1] = min(dp[i + 1], dp[i] * n + int(K[i]))
	else:
		val = 0
		for j in range(i, m):
			val = val * 10 + int(K[j])
			if val >= n: break
			dp[j + 1] = min(dp[j + 1], dp[i] * n + val)

print(dp[m])



#!/usr/bin/env python
# -*- coding: utf-8 -*-

n = int(input())
k = int(input())

arr = []
idx = 0
while k > 0:
    while 10 ** idx <= k and k % (10 ** idx) < n:
        idx += 1
    if k % (10 ** idx) >= n:
        idx -= 1
    while idx > 1 and k % (10 ** idx) == k % (10 ** (idx - 1)):
        idx -= 1
    arr.append(k % (10 ** idx))
    k //= (10 ** idx)
    idx = 0
mul = 1
sm = 0
for item in arr:
    sm += item * mul
    mul *= n
print(sm)


n = int(input())
k = list(map(int, list(input())))
m = len(k)
rec = [0] * (m + 1)
for i in range(m):
  u = rec[i] * n
  if k[i] > 0:
    d = 0
    for j in range(i, m):
      d = d*10 + k[j]
      if d >= n: break
      if rec[j+1]: rec[j+1] = min(rec[j+1], u+d)
      else: rec[j+1] = u+d
      #print(d, j+1, rec)
  else:    
    if rec[i+1]: rec[i+1] = min(rec[i+1], u)
    else: rec[i+1] = u
    #print(i, rec)
print(rec[-1])




def check(s, n):
    ans = 0
    if s != "":
        ans = int(s)
        
    return ans < n

n = int(input())
k = input()

s = ""
i = len(k) - 1

ans = 0
add = 1
while i >= 0:
    while i >= 0 and check(k[i] + s, n):
        s = k[i] + s
        i -= 1
    while len(s) > 1 and s[0] == '0':
        s = s[1:]
        i += 1

    
    ans += int(s) * add
    add *= n
    s = ""

print(ans)

import sys

dpp = [[0] * 100 for i in range(100)]
used = [[0] * 100 for i in range(100)]
inf = (1 << 300)

def dp(pos, i):
    if pos >= k:
        return '0'
    hh = n ** i
    if pos == k - 1:
        return str(int(s[pos]) * hh)
    if used[pos][i]:
        return dpp[pos][i]
    used[pos][i] = 1
    temp = s[pos]
    ans = inf
    best = '999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'
    ctr = pos
    while int(temp) < n:
        if (temp[0] == '0' and len(temp) > 1):
            if ctr == k - 1:
                break
            ctr += 1
            temp = s[ctr] + temp
            continue
        tt = dp(ctr + 1, i + 1)
        gg = str(int(tt) + int(temp) * hh)
        if (int(gg) < ans):
            ans = int(gg)
            best = gg
        if ctr == k - 1:
            break
        ctr += 1
        temp = s[ctr] + temp
    dpp[pos][i] = best
    return best
    

n = int(input())
s = input()[::-1]
k = len(s)
print(int(dp(0, 0)))




n = int(input())
k = input()
pos = len(k)
ans = []
while pos > 0:
    tmp = 0
    l = pos-1
    mark = l
    while l >= 0:
        a = int(k[l:pos])
        if a >= n:
            break
        else:
            if a != tmp: mark = l
            tmp = a
            l -= 1
            
    if tmp == 0:
        pos -= 1
        ans.append(0)
    else:
        pos = mark
        ans.append(tmp)

aans = 0
for i in ans[::-1]:
    aans = aans*n + i

print(aans)


# I'm feeling greedy
base = int(input())
num = input()

result = 0
place_value = 1
end = len(num)
while end > 0:
    begin = end - 1
    good_begin = begin
    while begin >= 0:
        if int(num[begin:end]) >= base:
            break
        elif num[begin] != '0':
            good_begin = begin
        begin -= 1
    begin = good_begin
    result += place_value * int(num[begin:end])
    place_value *= base
    end = begin

print(result)


base = int(input())
num = input()

a = 0
n = ''
l = []
sk = len(str(base))
while num:
    nn = num[-sk:]
    j = 0
    while int(nn) >= base:
        j += 1
        nn = nn[1:]
    while len(nn) > 1 and nn[0] == '0':
        j += 1
        nn = nn[1:]
    l.append(int(nn))
    num = num[:-sk+j]
    
p = 1
for n in l:
    a += p * n
    p *= base
print(a)


def solve(n, k):
    dp = [420] * (len(k) + 1)
    dp[-1] = 0
    idx = len(k) - 1
    n_num = int(n)
    while idx >= 0:
        if k[idx] != '0':
            for shift in range(1, len(k) - idx + 1):
                ok = int(k[idx:idx+shift]) < n_num
                if ok:
                    dp[idx] = min(
                        dp[idx], 1 + dp[idx+shift]
                    )
                else:
                    break
        else:
            dp[idx] = 1 + dp[idx+1]
        idx -= 1
    digits = list()
    idx = 0
    while idx < len(k):
        shift = 1
        while idx + shift <= len(k):
            if dp[idx+shift]+1 == dp[idx]:
                digits.append(int(k[idx:idx+shift]))
                break
            else:
                shift += 1
        idx += shift
    tot_res, n_pow = 0, 1
    for el in reversed(digits):
        tot_res += n_pow * el
        n_pow *= n_num
    return tot_res

N = input()
K = input()
print(solve(N, K))


n = int(input())
s = input()

prr = []
while len(s)>0:
    k = 0
    for i in range(len(s)-1,-1,-1):
        if(s[i]=='0'):
            continue
        if(int(s[i:])>=n or len(s[i:])>len(str(n))):
            k = i+1
            while(k<len(s) and s[k]=='0'):
                k += 1
            if(k==len(s)):
                k = len(s)-1
            break
#    print(k)
    prr.append(int(s[k:]))
    s = s[:k]
#print(prr)
sum = 0
for i in range(len(prr)-1, -1, -1):
    sum *= n
    sum += prr[i]

print(sum)

n = int(input())
k = input().strip()
power = [1]
for i in range(20):
    power.append(power[-1] * 10)
dp = [10 ** 18] * len(k)
for i in range(len(k)):
    for j in range(min(10, i + 1)):
        if k[i - j] == '0' and j > 0:
            continue
        s = int(k[i - j:i + 1])
        if s >= n:
            break
        if i - j > 0:
            dp[i] = min(dp[i], dp[i - j - 1] * n + s)
        else:
            dp[i] = min(dp[i], s)
print(dp[len(k) - 1])


n=input()
l=len(n)
n,k=int(n),input()
K,d,ans=[],1,0
while k:
    ll=l    
    while ll>len(k) or int(k[-ll:])>=n or k[-ll]=="0": 
        if ll>1: ll-=1
        else: break
    K+=[int(k[-ll:])];
    k=k[:-ll]
for x in K:
    ans+=x*d; d=d*n
print(ans)
    
    
    


#n = int(input())
#n, m = map(int, input().split())
n = input()
s = input()
#c = list(map(int, input().split()))
k = len(n)
n = int(n)
a = []
i = len(s) - 1
l = 0
while i - k + 1>= 0:
    if int(s[i - k + 1:i + 1]) < n:
        z = len(str(int((s[i - k + 1:i + 1]))))
        a.append(int(s[i - z + 1:i + 1]))
        i -= z
    else:
        z = len(str(int((s[i - k + 2:i + 1]))))
        a.append(int(s[i - z + 1:i + 1]))
        i -= z 
else:
    if i > - 1  and int(s[0:i + 1]) < n :
        a.append(int(s[0:i + 1]))
        i -= k

for i in range(len(a)):
    l += a[i] * (n ** i)
print(min(l, 10**18))

n=int(input())
#print(n)
d=input()
l=len(d)
dp=[[0,0] for i in range(0,l+1)]
dp[l-1]=[ord(d[l-1])-ord('0'),1]
for i in range(1,l):
	w=l-1-i;
	m=(ord(d[w])-ord('0'))*(n**i)+dp[w+1][0]
	dp[w]=[m,i+1];
	if (d[w]=='0'):
		dp[w][0]=dp[w+1][0]
		dp[w][1]=dp[w+1][1]+1
		continue
	for j in range(w,l):
		subs=int(d[w:j+1])
		u=dp[j+1]
		if subs<n:
			re=subs*(n**u[1])+u[0]
			if re<dp[w][0] or (re==dp[w][0] and 1+u[1]<dp[w][1]):
				dp[w][0]=re
				dp[w][1]=1+u[1]
		else:
			break
print(dp[0][0])


def main():
    QWE = 'trick'
    INF = 10 ** 18 + 9
    EPS = 10 ** -7

    import sys, math
    #fi = open('input.txt', 'r')
    #fo = open('output.txt', 'w+')
    #fi = open(QWE +".in", "r")
    #fo = open(QWE + ".out", "w+")
    
    n = input()
    ln = len(n)
    n = int(n);
    s = input()
    m = len(s)
    d = [0] * (m + 1)
    for i in range(1, m + 1):
        d[i] = INF
        for j in range(max(1, i - ln), i + 1):
            if s[j - 1] != '0' or j == i:
                q = int(s[j - 1: i])
                if q < n:
                    d[i] = min(d[i], d[j - 1] * n + q)
    print(d[m])
    #print(d)

main()


def getint(a):
	return int(''.join(map(str, a)))

b = int(input())
s = input()
s = list(map(int, list(s)))

n = len(s)

DP = [(-1,0) for i in range(n+1)]

for i in range(n-1, -1, -1):
	pass
	# print("At {}".format(i))
	for j in range(i+1, n+1):
		a = getint(s[i:j])
		pass
		# print(a)

		if(a >= b):
			break

		if(a > 9):
			t = DP[j]

			a = a * (b ** t[1])

			if(t[0] != -1):
				a += t[0]

			p = (a, t[1] + 1)

			if(DP[i][0] == -1):
				DP[i] = p
			else:
				if(DP[i][0] > p[0]):
					DP[i] = p
		else:
			t = DP[j]

			a = a * (b ** t[1])

			if(t[0] != -1):
				a += t[0]

			p = (a, t[1] + 1)

			if(DP[i][0] == -1):
				DP[i] = p
			else:
				if(DP[i][0] > p[0]):
					DP[i] = p
	pass
	# print("DP {}".format(DP[i]))

for i in range(n):
	pass
	# print(DP[i])

print(DP[0][0])

3

# BEGIN template
import sys
import re
import pprint

def dbg(x,y=''):
  if len(y) > 0: y += ' = '
  sys.stderr.write('\n>>> '+y+pprint.pformat(x)+'\n')
  sys.stderr.flush()

oo = 0x3f3f3f3f3f3f3f3f
# END template

def minn(x,y):
  if x[0] < y[0]: return x
  if x[0] > y[0]: return y
  if x[1] < y[1]: return x
  if x[1] > y[1]: return y
  return x

def main():
  n = int(input())
  s = input()
  m = len(s)
  s = '0'+s
  power = [1]
  for i in range(1,61):
    power.append(power[i-1]*n)
  dp = [(int(1e70),int(1e70))]*65
  dp[m+1] = (0,0)
  for i in range(m,0,-1):
    if s[i] == '0':
      tmp = dp[i+1]
      dp[i] = (1+tmp[0],tmp[1])
      continue
    for j in range(i,min(m+1,i+9)):
      d = int(s[i:j+1])
      if d >= n: break
      tmp = dp[j+1]
      dp[i] = minn(dp[i],(1+tmp[0],d*power[tmp[0]]+tmp[1]))
  print(dp[1][1])

main()



n=0
k=""
mem=[[-1 for xx in range(66)] for yy in range(66)]

def go(ind,po):
    nonlocal n
    nonlocal k
    nonlocal mem
    if ind>=len(k):
        return 0
    if mem[ind][po] != -1:
        return mem[ind][po]
    for i in range(ind,len(k)):
        cur=int((k[ind:i+1])[::-1])
        if (cur>=n):
            break
        if (k[i]=='0' and i != ind):
            continue
        if (mem[ind][po]==-1):
            if(go(i+1,po+1)!=-1):
                mem[ind][po]=cur*pow(n,po)+go(i+1,po+1)
        else:
            if(go(i+1,po+1)!=-1):
                mem[ind][po]=min(mem[ind][po],cur*pow(n,po)+go(i+1,po+1))
    return mem[ind][po]

n=int(input())
k=input()
k=k[::-1]

print(go(0,0))


import math

def binpow(x, y):
	ret = 1
	while y > 0:
		if y % 2 == 1:
			ret *= x
		x *= x
		y //= 2
	return ret

                   

n = int(input())
k = input()       
dp = [[-1 for i in range(100)] for j in range(100)]
#dp[i][j] = min(i, j)
dp[len(k)][0] = 0;
tmp = 0
for i in range(len(k), -1, -1):
	for j in range(1, len(k) + 1):
		tmp = 0
		for s in range(i, len(k)):
			tmp *= 10
			tmp += (ord(k[s]) - ord('0'));
			if tmp >= n:
				break
			if dp[s + 1][j - 1] != -1 and dp[i][j] == -1 or dp[s + 1][j - 1] + tmp * binpow(n, j - 1) < dp[i][j]:
				dp[i][j] = dp[s + 1][j - 1] + tmp * binpow(n, j - 1); 		 
			if s == i and k[s] == '0':
				break
			

#print(dp)
ans = 10 ** 18 + 1
for i in range(1, len(k) + 1):
	if dp[0][i] != -1:
		ans = min(ans, dp[0][i])
print(ans)