#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;
int n,m,visited[1005][1005],count;
char a[1005][1005];
queue<int>q1,q2;
int t[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};
void bfs(int sx,int sy) {
//cout<<"1111111";
q1.push(sx),q2.push(sy);
visited[sx][sy] = 1;
while(!(q1.empty() && q2.empty())) {
int nx = q1.front(),ny = q2.front();
q1.pop(),q2.pop();
for(int i = 0; i < 4; i++) {
int tx = t[i][0] + nx,ty = t[i][1] + ny;
if(tx > 0 && tx <= n && ty > 0 && ty <= m && visited[tx][ty] == 0 && a[tx][ty] == '#') {
q1.push(tx),q2.push(ty);
visited[tx][ty] = 1;
}
}
}
}
bool pd(int i,int j) {
int cnt = 0;
if(a[i][j] == '#') cnt++;
if(a[i][j+1] == '#') cnt++;
if(a[i+1][j] == '#') cnt++;
if(a[i+1][j+1] == '#') cnt++;
if(cnt == 3) return true;
else return false;
}
int main() {
cin>>n>>m;
for(int i = 1; i <= n; i++) {
scanf("%s",a[i] + 1);
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(pd(i,j)) {
cout<<"Bad placement.";
return 0;
}
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(visited[i][j] == 0 && a[i][j] == '#') {
//cout<<i<<" "<<j<<endl;
bfs(i,j);
count++;
}
}
}
cout<<"There are "<<count<<" ships.";
}