program PrimaCifMin;
var n, i, num, cif, cifmin, nummin, temp: integer;
begin
write('n= '); read(n);
write('introdu ',n,' numere naturale nenule:'); read(num);
nummin:=num;
while (num>0) do
begin
cif:=num mod 10;
num:=num div 10;
end;
cifmin:=cif;
for i:=2 to n do
begin
read(num);
temp:=num;
while (num>0) do
begin
cif:=num mod 10;
num:=num div 10;
end;
if cif<cifmin then begin cifmin:=cif; nummin:=temp; end
else begin
if cifmin=cif then if nummin<temp then nummin:=temp;
end;
end;
writeln('numarul cautat: ', nummin);
end.