why i get WA?? who can help me??
var a,b:array[1..100,1..100] of char;
ans:array[1..100,1..100] of integer;
m,n,i,j,top:integer;
procedure init;
var aa:array[1..100,1..100] of integer;
begin
fillchar(a,sizeof(a),' ');
readln(n,m);
for i:=1 to n do
for j:=1 to m do read(aa[i,j]);
for i:=1 to n do
for j:=1 to m do
if a[i,j]=' ' then
begin
if a[i,j+1]=a[i,j] then
begin
a[i,j]:='l';
a[i,j+1]:='r';
end else
begin
a[i,j]:='u';
a[i+1,j]:='b';
end;
end;
top:=0;
fillchar(b,sizeof(b),' ');
end;
procedure print;
var i,j:integer;
begin
for i:=1 to n do
begin
for j:=1 to m do write(ans[i,j],' ');
writeln;
end;
end;
function can(u,v,i:integer):boolean;
begin
if i=1 then
begin
if (a[u,v]<>'l')and(v+1<=m) then can:=true
else can:=false;
end else
begin
if (a[u,v]<>'u')and(u+1<=n) then can:=true
else can:=false;
end;
end;
procedure work(u,v:integer);
var i:integer;
begin
if (u=n+1)and(v=1) then begin print; halt; end;
if b[u,v]=' ' then
begin
for i:=1 to 2 do
if can(u,v,i) then
begin
inc(top);
if i=1 then
begin
b[u,v]:='l';
b[u,v+1]:='r';
ans[u,v]:=top;
ans[u,v+1]:=top;
end else
begin
b[u,v]:='u';
b[u+1,v]:='b';
ans[u,v]:=top;
ans[u+1,v]:=top;
end;
if v+1<=m then work(u,v+1)
else work(u+1,1);
if i=1 then
begin
b[u,v]:=' ';
b[u,v+1]:=' ';
end else
begin
b[u,v]:=' ';
b[u+1,v]:=' ';
end;
end;
end else
if v+1<=m then work(u,v+1)
else work(u+1,1);
end;
begin
init;
work(1,1);
writeln(-1);
end.