Const
Rn : String[36] = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
Function DecToN(a : Longint; Raz : Byte) : String;
Begin
If a>Raz-1 then DecToN:=DecToN(a div Raz,Raz)+Rn[(a mod Raz)+1]
else DecToN:=Rn[a+1];
end;
Begin
Writeln(DecToN(321,7)); { 636 }
end.