program white; {$APPTYPE CONSOLE} var a:array[0..101,0..101] of integer; b:array[0..10000] of integer; k,s,i,j,n,m:integer; c:char; procedure pr(x,y:integer); begin a[x,y]:=2; s:=s+1; if a[x-1,y]=1 then pr(x-1,y); if a[x+1,y]=1 then pr(x+1,y); if a[x,y-1]=1 then pr(x,y-1); if a[x,y+1]=1 then pr(x,y+1); end; begin assign(input,'white.DAT'); reset(input); assign(output,'white.SOL'); rewrite(output); readln(n,m); for i:=1 to n do for j:=1 to m do read(a[i,j]); k:=0; for i:=1 to n do for j:=1 to m do if a[i,j]=1 then begin b[s]:=b[s]+1;s:=0; pr(i,j);end; b[s]:=b[s]+1;s:=0; {for i:=1 to n do begin for j:=1 to m do write(a[i,j]); writeln; end;} for i:=1 to n*m do if b[i]>0 then k:=k+b[i]; writeln(k); for i:=1 to n*m do if b[i]>0 then writeln(i,' ',b[i]); close(input); close(output); end.