var  a:array[0..1000,0..1000] of integer;
  m,n,i,j,max,k,dl:longint;
  c:char;
  s:string;
procedure pop(x,y:longint);
begin
  a[x,y]:=0;
  inc(dl);
  if a[x+1,y]=1 then pop(x+1,y);
  if a[x,y+1]=1 then pop(x,y+1);
  if a[x-1,y]=1 then pop(x-1,y);
  if a[x,y-1]=1 then pop(x,y-1);
end;
begin

  readln(m,n);
  for i:=1 to m do
    begin
    for j:=1 to n do
    begin
      read(c);
      s:='';s:=s+c;
      val(s,a[i,j],max);
    end;
  readln(c);
  end;
  max:=0;
  k:=0;
  for i:=1 to m do
  for j:=1 to n do
  if a[i,j]=1 then
  begin
    dl:=0;
    inc(k);
    pop(i,j);
    if dl>max then max:=dl;
  end;
  write(k,' ',max);
  writeln;
end.
