# 그림 - BOJ

그림 - BOJ

from collections import deque

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

def bfs(x, y):
    area = 1
    q = deque()
    q.append((x, y))
    visit[x][y] = True

    while q:
        x, y = q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if nx < 0 or ny < 0 or nx >= n or ny >= m:
                continue
            if a[nx][ny] and not visit[nx][ny]:
                visit[nx][ny] = True
                q.append((nx, ny))
                area += 1
    return area

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
visit = [[False] * m for _ in range(n)]
pics = []
cnt = 0
for i in range(n):
    for j in range(m):
        if not visit[i][j] and a[i][j]:
            pics.append(bfs(i, j))
            cnt += 1
if not cnt:
    print(0)
    print(0)
else:
    print(cnt)
    print(max(pics))