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.util.*; 
            import java.math.*;
            import java.io.*;
            import java.text.DecimalFormat;
            import java.math.BigInteger;
            public class Main{
                //static int d=20;
                static long mod=1000000007 ;
                static HashMap<String,Double> hm=new HashMap<>(); 
                static ArrayList<ArrayList<Integer>> arr;
                static long[] dp1,dp2;
                static int[] a;
                static int[] vis,num;
                static long max;
                static int id;
                public static void main(String[] args)  throws IOException {
                    boolean online =false;
                    String fileName = "C-large-practice";
                    PrintWriter out; 
                    if (online) {
                        s.init(new FileInputStream(new File(fileName + ".in")));
                         out= new PrintWriter(new FileWriter(fileName + "out.txt"));
                    }
                     else {
                        s.init(System.in);   
                    
                        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
                    }//r,b,y,g
                    long n=s.nl();
                    String k=s.ns();
                    long ans=0;
                    //long pow=0;
                    //
                    long last=k.length()-1;
                    int m=k.length();
                    long[] dp=new long[m+1];
                    //long[] power=new long[m+1];
                    long[] pow=new long[m+1];
                    dp[m-1]=k.charAt(m-1)-'0';
                    //dp[m-1][1]=Long.MAX_VALUE;
                    pow[m-1]=1;
                    //pow[m][0]=1;
                    //long pow=1;
                    int flag=0;
                    for(int i=m-2;i>=0;i--){
                        //long two=Long.MAX_VALUE;
                        //out.println(pow);
                        int flag2=0;
                        long  u=(k.charAt(i)-'0')*1L;
                        //dp[i][0]=dp[i+1]+n*pow*u;
                        long x1=dp[i+1]+u*n*pow[i+1];
                      //  long x2=dp[i+1][1]+u*n*pow[i+1][1];
                       
                      
                            dp[i]=x1;
                            pow[i]=pow[i+1]*n;
                       
                        if(dp[i]<0)
                            dp[i]=Long.MAX_VALUE;
                        long mul=10;
                        if(u==0)
                            continue;
                        for(int j=i+1;j+1<=m;j++){
                            u=u*10+(k.charAt(j)-'0');
                           
                            if(u>=n)
                                break;
                            mul=pow[j+1]*n;
                            if(j+1==m)
                                mul=1;
                            long min=dp[j+1];
                            

                       
                            if(min+ u*mul<0 || u<0 || u*mul<0 || min<0 || mul<0){
                                
                                continue;
                            }
                            if(dp[i]>(min+u*mul)){
                                dp[i]=min+u*mul;
                                pow[i]=mul;
                            }
                          //  u=v;

                        }
                        
                        //flag=flag2;
                        //if(dp[i][0]<0 || dp[i][1]<0)
                        //out.println(dp[i]+" "+i);
                        
                    }
                    
                    ans=(dp[0]);
                    
                    out.println(ans);
                    
                    out.close();
     
                }
                public static long gcd(long a, long b){
                        if (a == 0) return b;
                        return gcd(b % a, a);
                }
                    
                public static boolean check(long x){
                    if(x%4==0 || x%7==0 || x%11==0)
                        return true;
                    if(x<4 || x<7 || x<11)
                        return false;
                    if(x%2==0){
                        return check(x/2);
                    }
                    else
                        return check(x/2) && check((x+1)/2);
                }
                public static int angle(int x1,int x2,int x3,int y1,int y2,int y3){
                    long val=(y2-y1)*1L*(x3-x2)-(y3-y2)*1L*(x2-x1);
                    if(val<0)
                        return 1;
                    else if(val>0)
                        return -1;
                    else
                        return 0;
                }
                
                static class BIT{
                
                    int N;
                    int tree[];
                    
                    BIT(int N){
                        this.N = N;
                        tree = new int[N + 1];
                    }
                    
                    void update(int idx){
                        while(idx <= N){
                            tree[idx]++;
                            idx += (idx & -idx);
                        }
                    }
                    
                    int query(int l,int r){
                        if(l == 1)
                            return read(r);
                        else
                            return read(r) - read(l-1);
                    }
                    
                    int read(int idx){
                        int sum = 0;
                        while(idx > 0){
                            sum += tree[idx];
                            idx -= (idx & -idx);
                        }
                        return sum;
                    }
                }
                public static boolean pal(String a){
                    int i=0;
                    int j=a.length()-1;
                    while(i<j){
                        if(a.charAt(i)!=a.charAt(j)){
                            return false;
                        }
                        i++;
                        j--;
                    }
                    return true;
                        
                }
                public static long find(long n,long k){
                    if(n==2){
                        if(k==1 || k==3)
                            return 1;
                        else
                            return 2;
                    }
                    long t=pow2(2,n,mod)-1;
                    long z=(t+1)/2;
                    if(k==z)
                        return n;
                    if(k<z)
                        return find(n-1,k);
                    else
                        return find(n-1,k-z);
                }
                public static long pow2(long a,long b,long mod){
                        long ans=1;
                        while(b>0){
                            if(b%2==1)
                                ans=(a*ans)%mod;
                            a=(a*a)%mod;
                            b/=2;
                        }
                        return  ans;
                }
                public static long pow3(long a,long b){
                        long ans=1;
                        while(b>0){
                            if(b%2==1)
                                ans=(a*ans);
                            a=(a*a);
                            b/=2;
                        }
                        return  ans;
                }
     
                 static class name implements Comparable<name> {
                    long l,b,h;
                    public name(long   x,long y,long z){
                        {
                            l=x;
                            b=y;
                        }
                        
                        
                        h=z;
                    }
                    public int compareTo(name o){
                        return -(int)(l*b-o.l*o.b);
                    }
                    
                }
                public static class s {
                    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 ns() throws IOException {
                        while ( ! tokenizer.hasMoreTokens() ) {
                            //TODO add check for eof if necessary
                            tokenizer = new StringTokenizer(
                                reader.readLine() );
                        }
                        return tokenizer.nextToken();
                    }
                
                    static int ni() throws IOException {
                        return Integer.parseInt( ns() );
                    }
                
                    static double nd() throws IOException {
                        return Double.parseDouble( ns() );
                    }
                    static long nl() throws IOException {
                        return Long.parseLong( ns() );
                    }
                }
            }
                    
