{
    ACM ICPC 2003-2004 NEERC

    Problem:    Alternative Scale of Notation
    Author:     Andrew Stankevich
    Solution:   Maxim Babenko
}


{$APPTYPE CONSOLE}

const
    inFile = 'alter.in';
    outFile = 'alter.out';

    maxL = 101;
    maxW = 400;

var
    b : integer;
    inp : array[1..maxW] of integer;
    ansLen : integer;
    answer : array[1..maxW] of integer;

procedure Solve;
var
    i, j : integer;
    a : integer;
    carry : integer;

begin
    ansLen := 0;
    for i := 1 to maxW do begin
        carry := 0;
        for j := maxW downto 1 do begin
            a := 10 * carry + inp[j];
            inp[j] := a div b;
            carry := a mod b;
        end;
        answer[i] := carry;
        if (carry <> 0) and (i > ansLen) then
            ansLen := i;
    end;

    carry := 0;
    for i := 1 to ansLen do begin
        a := answer[i] - carry;
        if (a = 0) and (i = ansLen) then begin
            dec(ansLen);
            break;
        end;
        carry := 0;
        while a <= 0 do begin
            inc(a, b);
            inc(carry);
        end;
        answer[i] := a;
    end;
end;

procedure ReadData;
var
    i : integer;
    s : string;

begin
    readln(b);
    if (b < 2) or (b > 9) then
        RunError(239);

    readln(s);
    if (length(s) > maxL) or ((length(s) = maxL) and (s <> '1' + stringofchar('0', maxL - 1)))  then
        RunError(239);

    fillchar(inp, sizeof(inp), 0);
    for i := 1 to length(s) do begin
        if (s[i] < '0') or (s[i] > '9') then
            RunError(239);
        inp[length(s) - i + 1] := ord(s[i]) - ord('0');
    end;

    close(input);
end;

procedure WriteData;
var
    i : integer;

begin
    for i := ansLen downto 1 do
        write(answer[i]);
    writeln;

    close(output);
end;

begin
    ReadData;
    Solve;
    WriteData;
end.
