type broi=array[1..100,1..100] of longint;
var n,p:byte;
    p1:broi;
procedure inp;
var i,j:byte;
begin
read(n,p);
for i:=1 to n do
for j:=1 to p do read(p1[i,j]);
writeln;
end;
function min4(n:byte):byte;
var c,i:longint;
begin
c:=p1[n,1];
min4:=1;
for i:=2 to p do if c>=p1[n,i] then begin
                                   c:=p1[n,i];
                                   min4:=i;
                                   end;
end;
function max4(n:byte):byte;
var c,i:longint;
begin
c:=p1[n,1];
for i:=2 to p do if c<=p1[n,i] then begin
                                   c:=p1[n,i];
                                   max4:=i;
                                   end;
end;
function simple(p1:broi):byte;
var i,j,c:byte;
begin
min4(1);
for i:=2 to n do begin
                 if max4(i)<>min4(i-1) then c:=min4(i-1)
                                       else begin
                                            c:=0;
                                            break;
                                            end;
                 end;
simple:=c;
end;
begin
inp;
writeln(simple(p1));
end.