const
    max_l = 200;
type
    tlong = array [1..max_l] of longint;

procedure readLong(var a: tlong);
var
    ch: char;
    i, l, t: longint;
begin 
    fillchar(a, sizeof(a), 0);
    l := 0;

    if seekeof then;
    read(ch);
    while ch in ['0'..'9'] do begin
        inc(l);
        a[l] := ord(ch) - ord('0');
        read(ch);
    end;
    for i := 1 to l div 2 do begin
        t := a[i]; a[i] := a[l - i + 1]; a[l - i + 1] := t;
    end;
end;

function ldivmod(var a: tlong; d: longint): longint;
var
    i: longint;
    p: longint;
begin
    p := 0;
    for i := max_l downto 1 do begin
        p := (p mod d) * 10 + a[i];
        a[i] := p div d;
    end;
    ldivmod := p mod d;
end;

procedure dec(var a: tlong);
var
    i: longint;
begin
    for i := 1 to max_l do begin
        if a[i] <> 0 then begin
            a[i] := a[i] - 1;
            break;
        end else begin
            a[i] := 9;
        end;
    end;
end;

function isZero(var a: tlong): boolean;
var
    i: longint;
begin
    for i := 1 to max_l do begin
        if a[i] <> 0 then begin
            isZero := false;
            exit;
        end;
    end;
    isZero := true;
end;

var
    i, b, q, l: longint;
    a: tlong;
    z: array [1..max_l * 10] of longint;
begin
    read(b);
    readLong(a);

    l := 0;
    while not isZero(a) do begin
        q := ldivmod(a, b);
        if q = 0 then begin
            q := b;
            dec(a);
        end;
        inc(l);
        z[l] := q;
    end;

    for i := l downto 1 do begin
        write(z[i]);
    end;
    writeln;

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