function sum_cifr(n: longword): word;
var i, res: longword;
begin
        res:= 0;
        while n <> 0 do
        begin
                res:= res + n mod 10;
                n:= n div 10;
        end;
        sum_cifr:= res;
end;

function prime(num: longword): boolean;
var i: longword;
begin
        if num = 2 then prime:= true
        else if num = 1 then prime:= false
        else
        begin
                for i:= 3 to round(sqrt(num)) do
                        if num mod i = 0 then prime:= false;
        end;
end;

function smith(num: longword): boolean;
var i, sum, sum0: longword;
begin
        sum:= 0;
        sum0:= sum_cifr(num);
        while num <> 1 do
        begin
                for i:= 1 to round(sqrt(num)) + 1 do
                        if (num mod i = 0) and prime(i) then
                        begin
                                num:= num div i;
                                sum:= sum + sum_cifr(i);
                        end;
        end;
        if sum0 = sum then smith:= true;
end;

var N, a, check, i: longword;
begin
        read(N);
        for i:= 1 to N - 1 do
        begin
                read(a);
                while not(smith(a + 1)) do
                        inc(a);
                write(a, ' ');
        end;
        read(a);
        while not(smith(a + 1)) do
                inc(a);
        write(a);
end.
