import java.util.Scanner;
public class Main
{
static void convert(int n,int r)
{
int[] a = new int[8];
int i = 0;
for(; i < 8 && n != 0; i++)
{
a[i] = n % r;
n = n / r;
}
i--;
StringBuffer sb = new StringBuffer();
for(; i >= 0; i--)
{
if(a[i] > 9)
{
sb.append((char)(a[i] - 10 + 'A'));
}
else
{
sb.append(a[i]);
}
}
System.out.println(sb.toString());
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int r = sc.nextInt();
if(n == 0)
{
System.out.println(0);
return;
}
convert(n, r);
}
}