
import java.io.*;
import java.awt.*;

// Input is one group of the following:
//
//   a pair of numbers (the initial base and target base)
//   a string representing the number
//
// Note that this third item MUST be in quotes if it contains only
// digits. 
//
// The input is assumed to be correct.

class NIBTester {

   public static void main (String[] args) throws IOException {

        InputStream inStream = System.in;
        StreamTokenizer dStream = new StreamTokenizer (inStream);
        
        // The old and new bases.
        int oldBase, newBase;

        int ttype = dStream.nextToken ();
        oldBase = (int) dStream.nval;
        
        ttype = dStream.nextToken ();
        newBase = (int) dStream.nval;
        
        ttype = dStream.nextToken ();
        String num = dStream.sval;
            
        NIB n1 = new NIB(num,oldBase);
        NIB n2 = n1.convertTo(newBase);

        System.out.println (n2);

    }                                                      
}
