var i, j, n, m, mn: longint;
a: array[1..1000,1..1000] of longint;
begin
write('N = ');
readln(n);
write('M = ');
readln(m);
writeln('Матрица:');
for i := 1 to n do
for j := 1 to m do
read(a[i,j]);
for j := 1 to m do
begin
mn := a[1,j];
for i := 2 to n do
if a[i,j] < mn then mn := a[i,j];
for i := 1 to n do
if a[i,j] < 0 then a[i,j] := mn;
end;
writeln('Результат:');
for i := 1 to n do
begin
for j := 1 to m do
write(a[i,j], ' ');
writeln;
end;
end.