#include<iostream>
#include<queue>
using namespace std;
int r, c, map[100][100];
bool isHole[100][100];
int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, -1, 0, 1 };
bool isInside(int x, int y) {
return (0 <= x && x < r && 0 <= y && y < c);
}
int getCheese(void) {
int res = 0;
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
if (map[i][j] == 1) res++;
return res;
}
void checkHole(void) {
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
isHole[i][j] = true;
queue<pair<int, int>> q;
bool visited[100][100] = {};
q.push({ 0, 0 });
isHole[0][0] = false;
visited[0][0] = true;
while (!q.empty()) {
int curX = q.front().first, curY = q.front().second;
q.pop();
for (int i = 0; i < 4; i++) {
int nextX = curX + dx[i], nextY = curY + dy[i];
if (!isInside(nextX, nextY)) continue;
if (visited[nextX][nextY]) continue;
if (map[nextX][nextY] == 1) continue;
visited[nextX][nextY] = 1;
isHole[nextX][nextY] = false;
q.push({ nextX, nextY });
}
}
return;
}
void meltingCheese(void) {
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (map[i][j] == 1) { // 치즈가 녹는지 체크하자!
for (int k = 0; k < 4; k++) {
int nextX = i + dx[k], nextY = j + dy[k];
if (isInside(nextX, nextY) && map[nextX][nextY] == 0 && !isHole[nextX][nextY]) {
map[i][j] = 0;
break;
}
}
}
}
}
return;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> r >> c;
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
cin >> map[i][j];
int time = 0, cheese;
while (1) {
int curCheese = getCheese();
if (!curCheese) break; // 현재 cheese가 없으면 끝!
checkHole(); // 구멍인 '0' 아닌 '0'을 따로 체크!
meltingCheese(); // 치즈를 녹이자
cheese = curCheese;
time++;
}
cout << time << '\n' << cheese << '\n';
return 0;
}