program paskal;

type
pcvor=^cvor;
cvor=record
broj:integer;
protok:integer;
sled:pcvor;
levi:pcvor;
desni:pcvor;
end;
var 
g:array[1..1000000] of pcvor;
t,m,n,b,t1,c,e:integer;
procedure addbeg1(var poc:pcvor;br:integer);
var novi:pcvor;
begin
new(novi);
novi^.broj:=br;
novi^.sled:=poc;
novi^.levi:=poc;
novi^.desni:=poc;
poc:=novi;
g[t]:=novi;
novi^.protok:=1;
end;
procedure addend1(var poc:pcvor;br:integer);
var tek,novi:pcvor;
begin
novi^.protok:=0;
new(novi);
novi^.broj:=br;
tek:=poc;
if poc<>nil then begin
while tek^.sled<>nil do
tek:=tek^.sled;
tek^.sled:=novi;
end
else poc:=novi;
novi^.sled:=nil;
novi^.desni:=nil;
novi^.levi:=nil;
end;
procedure addend2(var poc:pcvor;br:integer);
var tek,novi:pcvor;
begin
novi^.protok:=0;
new(novi);
novi^.broj:=br;
tek:=poc;
if poc<>nil then begin
while tek^.levi<>nil do
tek:=tek^.levi;
tek^.levi:=novi;
end
else poc:=novi;
novi^.levi:=nil;
novi^.desni:=nil;
novi^.sled:=nil;
end;
procedure addend3(var poc:pcvor;br:integer);
var tek,novi:pcvor;
begin
novi^.protok:=0;
new(novi);
novi^.broj:=br;
tek:=poc;
if poc<>nil then begin
while tek^.desni<>nil do
tek:=tek^.desni;
tek^.desni:=novi;
end
else poc:=novi;
novi^.desni:=nil;
novi^.sled:=nil;
novi^.levi:=nil;
end;



begin
e:=5;
read(m,n);
for t:=1 to m do
begin
read(b);
g[t]:=@e;
addbeg1(g[t],b);
end;
for t:=2 to n do
for t1:=1 to m do
begin                               
read(c);
addend1(g[t1],c);
if t1<>m then 
addend2(g[t1+1],c);
if t1>1 then
addend3(g[t1-1],c);
end;
for t:=1 to m do
begin

    if g[t]^.broj=1 then
    begin
    g[t]:=g[t]^.sled;
    g[t]^.protok:=g[t]^.protok+1;
    end
    else
    begin
    if m mod 2 =0 then  
    begin
    if t>1 then
      g[t]:=g[t]^.levi
      else  g[t]:=g[t]^.desni;
    g[t]^.protok:=g[t]^.protok+1;
    end
    else
    begin
    if t<>m then
      g[t]:=g[t]^.desni
      else  g[t]:=g[t]^.levi;
    g[t]^.protok:=g[t]^.protok+1;
    end
    end;
end;
for t:=1 to m do
write(g[t]^.protok);
end.