program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

Var
    f,g:textfile;
    i,j,plmax,sch,n,m:integer;
    a:array[1..6,1..7] of byte;
    c:string;
    c1,q,max:integer;
procedure rec(i,j:integer);
begin
      if a[i,j+1]=1 then begin plmax:=plmax+1; a[i,j+1]:=0; j:=j+1; rec(i,j); end;
      if a[i,j-1]=1 then begin plmax:=plmax+1; a[i,j-1]:=0; j:=j-1; rec(i,j); end;
      if a[i+1,j]=1 then begin plmax:=plmax+1; a[i+1,j]:=0; i:=i+1; rec(i,j); end;
      if a[i-1,j]=1 then begin plmax:=plmax+1; a[i-1,j]:=0; i:=i-1; rec(i,j); end;
end;
begin
    assignfile(f,'STDIN.txt');
    assignfile(g,'STDOUT.txt');
    reset(f);
    read(f,n,m);
    rewrite(g);
    sch:=0; plmax:=1;   max:=0;
    for i:=1 to n do
    begin
          readln(f,c1);
          c:=IntToStr(c1);
          q:=length(c);
          while q<7 do
          begin
          c:='0'+c;
          q:=q+1;
          end;
          for j:=1 to m do
          begin
                a[i,j]:=StrToInt(c[j]);
          end;
    end;
    for i:=1 to n do
    begin
        for j:=1 to m do
        begin
              if a[i,j]=1 then
              begin
              a[i,j]:=0;
              rec(i,j);
              sch:=sch+1;
              If plmax>max then max:=plmax;
              plmax:=1;
              end;
        end;
    end;
    closefile(f);
    closefile(g);
    writeln(max,'   ',sch);
    readln;readln;
end.
