# include <stdio.h>
void output(int n, int r)
{
char tab[] = "0123456789ABCDEFGHIJKLMN" ;
if (n == 0) return ;
output (n/r, r) ;
printf ("%c", tab[n%r]) ;
}
int main ()
{
int n, r ;
while (scanf ("%d%d", &n, &r))
{
if (n < 0){
printf ("-") ;
n = -n ;
}
output(n,r) ;//把n用r进制输出
printf ("\n") ;
}
return 0 ;
}