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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class q5 {
	static ArrayList<Integer>[] gph,rpgh;
	static HashMap<Integer,Long>[] gph2;
	static long[][][] dp;
	
	static String solve(long v,int n) {
		String a="";
		while(v>0) {
			long r=v%n;
			a=r+a;
			v/=n;
		}
		return a;
	}
	
	
	public static void main(String[] args) throws IOException {
		
		Reader.init(System.in);
		PrintWriter out=new PrintWriter(System.out);
		StringBuffer output=new StringBuffer("");
		int n=Reader.nextInt();
		String k=Reader.next();
		ArrayList<Long> part=new ArrayList<Long>();
		StringBuffer prev=new StringBuffer("");
		boolean consec=false;int count=0;
		for(int i=k.length()-1;i>=0;i--) {
			String news=k.charAt(i)+prev.toString();
			//long v=Long.parseLong(news);
			BigInteger v=new BigInteger(news);
			BigInteger nn=BigInteger.valueOf(n);
			if(v.compareTo(nn)!=-1) {
				long vv=Long.parseLong(prev.toString());
				if(vv!=0)
				part.add(vv);
				prev=new StringBuffer("");
				if(consec) {
					consec=false;
					StringBuffer b2=new StringBuffer(""+k.charAt(i));
					BigInteger preve=new BigInteger(b2.toString());
					//long preve=val;
					b2.append(0);count--;
					BigInteger val=new BigInteger(b2.toString());
					while(val.compareTo(nn)==-1 && count>0) {
						preve=val;
						b2.append(0);
						val=new BigInteger(b2.toString());
						count--;
					}
					if(val.compareTo(nn)==-1) {
						i--;
						prev=new StringBuffer(val.toString());
					}
					else {
						count++;
						while(count!=0) {
						part.add((long)0);
						count--;
						}
						i--;
						prev=new StringBuffer(preve.toString());count=0;
					}
					count=0;
				}
				
				i++;
			}
			else {
				if(k.charAt(i)=='0') {
					consec=true;count++;
				}
				else {
					consec=false;count=0;
				}
				prev.insert(0, k.charAt(i));
			}
		}
		part.add(Long.parseLong(prev.toString()));
		int nn=part.size();
		long f=1;
		long ans=0;
		for(int i=0;i<nn;i++) {
			ans+=f*part.get(i);
			f*=n;
		}
		output.append(ans);
//		long low=1;
//		long high=(long) 1e18;
//		long ans=0;
//		BigInteger b=new BigInteger(k);
//		while(low<=high) {
//			long mid=(low+high)/2;
//			BigInteger b2=new BigInteger(solve(mid,n));
//			int l=b.compareTo(b2);
//			if(l==1) {
//				low=mid+1;
//			}
//			else if(l==0) {
//				ans=mid;
//				high=mid-1;
//			}
//			else {
//				high=mid-1;
//			}
//		}
//		output.append(ans);
		out.write(output.toString());
		out.flush();
		
	}
}
class NoD{
	int a,b;
	String s;
	
	NoD(int aa,int bb){
		a=aa;b=bb;
		s=a+" "+b;
		
	}
	@Override
	public boolean equals(Object o) {
		if(o!=null && o.getClass()==getClass()) {
			NoD c= (NoD) o;
			return c.a==a && c.b==b;
		}
		return false;
	}
	@Override
	public int hashCode() {
		return s.hashCode();
	}
}
class NoD2{
	int a,b;
	long val;
	NoD2(int aa,int bb, long c){
		a=aa;b=bb;val=c;
	}
}
class DisJ{
	 int[] parent,rank;
	 DisJ(int n){
		 parent=new int[n+1];
		 rank=new int[n+1];
		 for(int i=1;i<=n;i++) {
			 rank[i]=0;
			 parent[i]=i;
		 }
	 }
	void union(int a, int b) {
		int p1=find(a);
		int p2=find(b);
		if(p1!=p2) {
			if(rank[p1]>=rank[p2]) {
				parent[p2]=p1;
				if(rank[p1]==rank[p2]) rank[p1]++;
			}
			else {
				parent[p1]=p2;
			}
		}
	}
	
	int find(int a) {
		if(a!=parent[a]) {
			parent[a]=find(parent[a]);
		}
		return parent[a];
	}
}

//class Seg{
//	ArrayList<Integer> arr;
//	int[] segtree;
//	Seg(ArrayList<Integer> a){
//		arr=a;
//		int n=arr.size();
//		segtree=new int[4*n+1];
//	}
//	
//	void build(int index, int l, int r) {
//		if(l==r) {
//			segtree[index]=q5.occurance[arr.get(l)];
//		}
//		else {
//			int middle=(l+r)/2;
//			build(2*index+1,l,middle);
//			build(2*index+2,middle+1,r);
//			segtree[index]=Math.min(segtree[2*index+1], segtree[2*index+2]);
//		}
//	}
//	
//	int query(int index, int l, int r, int ql, int qr) {
//		if(ql<=l && r<=qr) {
//			return segtree[index];
//		}
//		else if(qr<l || ql>r) {
//			return Integer.MAX_VALUE;
//		}
//		else {
//			int middle=(l+r)/2;
//			int left=query(2*index+1,l,middle,ql,qr);
//			int right=query(2*index+2,middle+1,r,ql,qr);
//			return Math.min(left, right);
//		}
//	}
//}
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
 
    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
 
    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}

