#include
char map[100][100];
int n, m;
int total, maxArea, area;
void GetMap()
{
scanf("%d%d\n", &n, &m);
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
scanf("%c", &map[i][j]);
}
getchar();
}
}
void Search(int x, int y)
{
if (x < 0 || x >= n || y < 0 || y >= m || map[x][y] == '.')
{
return;
}
++area;
map[x][y] = '.';
Search(x - 1, y - 1);
Search(x - 1, y);
Search(x - 1, y + 1);
Search(x, y - 1);
Search(x, y + 1);
Search(x + 1, y - 1);
Search(x + 1, y);
Search(x + 1, y + 1);
}
void GetResult()
{
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
if (map[i][j] == 'I')
{
++total;
area = 0;
Search(i, j);
if (maxArea < area)
{
maxArea = area;
}
}
}
}
}
int main()
{
GetMap();
GetResult();
printf("%d %d\n", total, maxArea);
return 0;
}