{
    ACM ICPC 2003-2004 NEERC

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

{$APPTYPE CONSOLE}
{$O-,Q+,R+}
{$DEFINE ALLOWMULTITEST}

program alternative_scale_of_notation;

const
    maxd = 400;

var
    i, j, b, l, c: longint;
    s: string;
    a: array [0..maxd] of longint;

begin

    if eoln then runerror(239);
    read(b);
    if (b < 2) or (b > 9) then runerror(239);
    if not eoln then runerror(239);
    readln;
    readln(s);
    {$IFNDEF ALLOWMULTITEST}
    if not eof then runerror(239);
    {$ENDIF}
    if (s = '') or (length(s) > 101) then runerror(239);
    for i := 1 to length(s) do
        if not (s[i] in ['0'..'9']) then runerror(239);
    if (s[1] = '0') and (length(S) > 1) then runerror(239);
    if (length(s) = 101) then
    begin
        if s[1] <> '1' then runerror(239);
        for i := 2 to length(s) do
            if s[i] <> '0' then runerror(239);
    end;

    l := 0;
    for i := 1 to length(s) do
    begin
        c := ord(s[i]) - ord('0');
        for j := 1 to l do
        begin
            c := c + a[j] * 10;
            a[j] := c mod b;
            c := c div b;
        end;
        while c > 0 do
        begin
            inc(l);
            a[l] := c mod b;
            c := c div b;
        end;
    end;
    for i := 1 to l - 1 do
    begin
        while a[i] <= 0 do
        begin
            inc(a[i], b);
            dec(a[i + 1]);
        end;
    end;
    if (l > 0) and (a[l] < 0) then
        runerror(240);
    while (l > 0) and (a[l] = 0) do
        dec(l);

    for i := l downto 1 do
        write(a[i]);


    close(input);
    close(output);
end.
