program n_1;
uses crt;
var
n: longint;
k: integer;
function Sym(n: integer): char;
begin
case n of
0..9: Sym := chr(48 + n);
10..36: Sym := chr(55 + n);
end;
end;
function funct(n: longint; k: integer): string;
var
st: string;
begin
st := '';
if n = 0 then st := '0' else
begin
while n >= 1 do
begin
st := Sym(n mod k) + st;
n := n div k;
end;
end;
DecToX := st;
end;
begin
readln(n);
repeat
readln(k);
until (2
writeln(funct(n, k));
end.