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·162 + 13·161 + 11·160). 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 ≤ 109). The second line contains the integer k (0 ≤ k < 1060), 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 1018.

The number k doesn't contain leading zeros.

Output

Print the number x (0 ≤ x ≤ 1018) — 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·130 or 15 = 1·131 + 2·130.
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.Map.Entry;

public class FastIO2 {
	static long mod = (int) (1e9 + 7);

	static void solve() {
		int t = 1;
		while (t-- > 0) {
			long n = l();
			char[] a = stoc(s());
			long[][] dp = new long[a.length + 2][a.length + 2];
			int i = 1;
			for (int l = 1; l <= a.length - i + 1; l++) {
				int j = i + l - 1;
				long num = 0;
				long prod = 1;
				dp[i][j] = Long.MAX_VALUE;
				for (int k = j; k >= i; k--) {
					num = prod * (a[k - 1] - '0') + num;
					long t1 = prod;
					prod *= 10;
					if(prod/10!=t1)
						break;
					if (num < n) {
						if (!(k < j && a[k - 1] == '0')) {
							long x = dp[i][k - 1];
							long y = n;
							long temp = x*y;
							if((x!=0 && temp/x==y)||(x==0))
							dp[i][j] = Math.min(dp[i][j], n * dp[i][k - 1]
									+ num);
						}
					} else {
						break;
					}
				}
			}
			//out.println(Arrays.toString(dp[1]));
			out.println(dp[1][a.length]);
		}
		out.close();
	}

	static class Pair implements Comparable<Pair> {
		int val;
		int idx;

		public Pair(int idx, int val) {
			this.idx = idx;
			this.val = val;
		}

		@Override
		public int compareTo(Pair arg0) {
			// TODO Auto-generated method stub
			int x = Integer.compare(val, arg0.val);
			if (x != 0)
				return x;
			return Integer.compare(idx, arg0.idx);
		}

		public String toString() {
			return idx + " " + val;
		}
	}

	static void traverse(int n, long[] dp, long[] dp2) {
		for (int i = 0; i < (1 << n); i++) {
			int submask = (i - 1) & i;
			while (submask > 0) {
				dp[i] = Math.min(dp[i], dp2[i ^ submask] + dp[submask]);
				submask = (submask - 1) & i;
			}
		}
	}

	static long[][] exp(long[][] a, long n) {
		if (n == 0)
			return getIdentity(3);
		long[][] ans = exp(a, n / 2);
		ans = mul(ans, ans, 3);
		if ((n & 1) == 1)
			ans = mul(ans, a, 3);
		return ans;
	}

	static long[][] getIdentity(int dim) {
		long[][] c = new long[dim][dim];
		for (int i = 0; i < dim; i++) {
			c[i][i] = 1l;
		}
		return c;
	}

	static long[][] mul(long[][] a, long[][] b, int dim) {
		long[][] c = new long[dim][dim];
		for (int i = 0; i < dim; i++) {
			for (int j = 0; j < dim; j++) {
				for (int k = 0; k < dim; k++) {
					c[i][j] += (a[i][k] * b[k][j]) % mod;
					c[i][j] %= mod;
				}
			}
		}
		return c;
	}

	public static int[] generatePrimes(int n) {
		boolean[] prime = new boolean[n + 1];
		Arrays.fill(prime, 2, n + 1, true);
		for (int i = 2; i * i <= n; i++)
			if (prime[i])
				for (int j = i * i; j <= n; j += i)
					prime[j] = false;
		int[] primes = new int[n + 1];
		int cnt = 0;
		for (int i = 0; i < prime.length; i++)
			if (prime[i])
				primes[cnt++] = i;

		return Arrays.copyOf(primes, cnt);
	}

	public static int[] generatePrimesLinear(int n) {
		int[] lp = new int[n + 1];
		int[] primes = new int[n + 1];
		int cnt = 0;
		for (int i = 2; i <= n; ++i) {
			if (lp[i] == 0) {
				lp[i] = i;
				primes[cnt++] = i;
			}
			for (int j = 0; j < cnt && primes[j] <= lp[i] && i * primes[j] <= n; ++j)
				lp[i * primes[j]] = primes[j];
		}
		return Arrays.copyOf(primes, cnt);
	}

	public static boolean isPrime(long n) {
		if (n <= 1)
			return false;
		for (long i = 2; i * i <= n; i++)
			if (n % i == 0)
				return false;
		return true;
	}

	public static int[] numberOfPrimeDivisors(int n) {
		int[] divisors = new int[n + 1];
		Arrays.fill(divisors, 2, n + 1, 1);
		for (int i = 2; i * i <= n; ++i)
			if (divisors[i] == 1)
				for (int j = i; j * i <= n; j++)
					divisors[j * i] = divisors[j] + 1;
		return divisors;
	}

	public static int[] generateDivisorTable(int n) {
		int[] divisor = new int[n + 1];
		for (int i = 1; i <= n; i++)
			divisor[i] = i;
		for (int i = 2; i * i <= n; i++)
			if (divisor[i] == i)
				for (int j = i * i; j <= n; j += i)
					divisor[j] = i;
		return divisor;
	}

	public static int phi(int n) {
		int res = n;
		for (int i = 2; i * i <= n; i++)
			if (n % i == 0) {
				while (n % i == 0)
					n /= i;
				res -= res / i;
			}
		if (n > 1)
			res -= res / n;
		return res;
	}

	public static int[] generatePhi(int n) {
		int[] res = new int[n + 1];
		for (int i = 1; i <= n; i++)
			res[i] = i;
		for (int i = 1; i <= n; i++)
			for (int j = i + i; j <= n; j += i)
				res[j] -= res[i];
		return res;
	}

	static long gcd(long m, long n) {
		long x;
		long y;
		while (m % n != 0) {
			x = n;
			y = m % n;
			m = x;
			n = y;
		}
		return n;
	}

	static long lcm(long a, long b) {
		if (a == 0 && b == 0) {
			return 0;
		}

		long result = a;
		long gcd = gcd(a, b);
		result /= gcd;
		result *= b;
		result = Math.abs(result);
		return result;
	}

	static long modPow(long a, long b, long mod) {
		long res = 1, pow = a;
		while (b > 0) {
			if ((b & 1) == 1) {
				res = (pow * res) % mod;
			}
			pow = (pow * pow) % mod;
			b = b / 2;
		}
		return res;
	}

	public static long modInverse(long a, long p) {
		// (assuming p is prime).
		return modPow(a, p - 2, p);
	}

	public static long nCk(long y, long z) {
		if (y < z) {
			return 0;
		}
		if (y == z || z == 0) {
			return 1;
		}

		if (z == 1) {
			return y % mod;
		}

		// Left to right associativity between * and %
		return (((factorials[(int) y] * invFact[(int) z]) % mod) * invFact[(int) (y - z)])
				% mod;
	}

	static BigInteger b(long a) {
		return BigInteger.valueOf(a);
	}

	static long[] factorials, invFact;

	static void computeFactorials(int N) {
		factorials = new long[N];
		invFact = new long[N];
		factorials[0] = 1;
		for (int i = 1; i < factorials.length; i++) {
			factorials[i] = (factorials[i - 1] * i) % mod;
		}

		for (int i = 0; i < invFact.length; i++)
			invFact[i] = modPow(factorials[i], mod - 2, mod);
	}

	static long[][] generateNCR(int n, long mod) {
		long ncr[][] = new long[n + 1][n + 1];
		ncr[0][0] = 1;
		for (int i = 1; i <= n; i++) {
			ncr[i][0] = 1;
			ncr[0][i] = 0;
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				ncr[i][j] = (ncr[i - 1][j] + ncr[i - 1][j - 1]) % mod;
			}
		}
		return ncr;
	}

	static long lucas(long n, long k, long[][] ncr) {
		long ans = 1;
		while (n > 0) {
			int N = (int) (n % mod);
			int K = (int) (k % mod);
			if (K > N)
				return 0;
			ans *= (ncr[N][K]);
			n /= mod;
			k /= mod;
		}
		return ans % mod;
	}

	static BigInteger Bigpow(BigInteger n, BigInteger a) {
		BigInteger res = b(1), pow = n;
		while (a.compareTo(b(0)) > 0) {
			if ((a.and(b(1))).compareTo(b(1)) == 0) {
				res = pow.multiply(res);
			}
			pow = pow.multiply(pow);
			a = a.divide(b(2));
		}
		return res;
	}

	static void sortint(int[] arr) {
		int len = arr.length;
		if (len == 1)
			return;
		int j, k;
		int tem;
		Random random = new Random();
		for (int i = 0; i < 3 * len; i++) {
			j = random.nextInt(len - 1);
			k = random.nextInt(len - j) + j + 1;
			tem = arr[j];
			arr[j] = arr[k];
			arr[k] = tem;
		}
		Arrays.sort(arr);
	}

	static void sortlong(long[] arr) {
		int len = arr.length;
		if (len == 1)
			return;
		int j, k;
		long tem;
		Random random = new Random();
		for (int i = 0; i < 3 * len; i++) {
			j = random.nextInt(len - 1);
			k = random.nextInt(len - j) + j + 1;
			tem = arr[j];
			arr[j] = arr[k];
			arr[k] = tem;
		}
		Arrays.sort(arr);
	}

	static class MyArrayListL implements List<Long> {

		private long[] myStore;
		private int actSize = 0;

		public MyArrayListL() {
			myStore = new long[2];
		}

		public Long get(int index) {
			return myStore[index];
		}

		public void add(long obj) {
			if (myStore.length - actSize <= 1)
				increaseListSize();
			myStore[actSize++] = obj;
		}

		public int size() {
			return actSize;
		}

		public void clear() {
			actSize = 0;
		}

		private void increaseListSize() {
			myStore = Arrays.copyOf(myStore, myStore.length * 2);
		}

		@Override
		public boolean add(Long arg0) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public void add(int arg0, Long arg1) {
			// TODO Auto-generated method stub

		}

		@Override
		public boolean addAll(Collection<? extends Long> arg0) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean addAll(int arg0, Collection<? extends Long> arg1) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean contains(Object arg0) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean containsAll(Collection<?> arg0) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public int indexOf(Object arg0) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public boolean isEmpty() {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public Iterator<Long> iterator() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public int lastIndexOf(Object arg0) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public ListIterator<Long> listIterator() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public ListIterator<Long> listIterator(int arg0) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public boolean remove(Object arg0) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public Long remove(int arg0) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public boolean removeAll(Collection<?> arg0) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean retainAll(Collection<?> arg0) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public Long set(int arg0, Long arg1) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public List<Long> subList(int arg0, int arg1) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public Object[] toArray() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public <T> T[] toArray(T[] arg0) {
			// TODO Auto-generated method stub
			return null;
		}
	}

	public static void main(String args[]) {
		new Thread(null, new Runnable() {
			public void run() {
				solve();
			}
		}, "1", 1 << 26).start();
	}

	static InputReader in = new InputReader(System.in);
	static OutputWriter out = new OutputWriter(System.out);

	static int i() {
		return in.readInt();
	}

	static long l() {
		return in.readLong();
	}

	static double d() {
		return in.readDouble();
	}

	static String s() {
		return in.readString();
	}

	static int[] Iarr(int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++) {
			array[i] = i();
		}
		return array;
	}

	static long[] Larr(int size) {
		long[] array = new long[size];
		for (int i = 0; i < size; i++) {
			array[i] = l();
		}
		return array;
	}

	static double[] Darr(int size) {
		double[] array = new double[size];
		for (int i = 0; i < size; i++) {
			array[i] = d();
		}
		return array;
	}

	static String[] Sarr(int size) {
		String[] array = new String[size];
		for (int i = 0; i < size; i++) {
			array[i] = s();
		}
		return array;
	}

	static char[] stoc(String ss) {
		return ss.toCharArray();
	}

	private static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next() {
			return readString();
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	private static class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
					outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}

		public void flush() {
			writer.flush();
		}
	}
}