#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
char mp[N][N];
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int n, m;
int ant = 0;
struct Pos
{
int x;
int y;
};
bool cheak()
{
int cnt = 0;
for (int i = 0; i < n - 1; ++i)
{
for (int j = 0; j < m - 1; ++j)
{
if (mp[i][j] == '#')
cnt++;
if (mp[i + 1][j] == '#')
cnt++;
if (mp[i][j + 1] == '#')
cnt++;
if (mp[i + 1][j + 1] == '#')
cnt++;
if (cnt == 3) return true;
else cnt=0;
}
}
return false;
}
void bfs(Pos p)
{
queue<Pos> que;
que.push(p);
++ant;
mp[p.x][p.y] = '.';
while (!que.empty())
{
auto pf = que.front();
int sx = pf.x, sy = pf.y;
mp[sx][sy] = '.';
que.pop();
for (int i = 0; i < 4; ++i)
{
int nx = sx + dx[i], ny = sy + dy[i];
if (nx >= 0 && nx < n && ny >= 0 && ny < m && mp[nx][ny] == '#')
{
mp[nx][ny] == '.';
que.push(Pos{nx, ny});
mp[sx][sy] = '.';
}
}
}
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
cin >> mp[i][j];
if (cheak())
{
printf("Bad placement.");
}
else
{
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
if (mp[i][j] == '#')
{
bfs(Pos{i, j});
}
}
}
printf("There are %d ships.", ant);
}
return 0;
}