var  a:array[0..1000,0..1000] of byte;
  m,n,i,j,max,k,dl:longint;
  c:char;
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
  assign(input,'STDIN');
  assign(output,'STDOUT');
  reset(input);
  rewrite(output);
  readln(m,n);
  for i:=1 to m do
  begin
  for j:=1 to n do
  begin
    read(c);
    a[i,j]:=ord(c)-48;
  end;
    if i=m then break;
    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);
end.
