for i := 1 to n do
for j := 1 to n do
begin
if B[i,j]>0 then
begin
A[i] := B[i,j];
break;
end;
if j = n then A[i] := -1;
end;
for i := 1 to n do
for j := 1 to n do
begin
if B[i,j]>0 then
begin
A[i] := B[i,j];
break;
end;
if j = n then A[i] := -1;
end;