#include<bits/stdc++.h>
using namespace std;
bool k[1005][1005];
int main() {
int r,c;
scanf("%d%d",&r,&c);
char b;
for(int i = 1;i <= r;i++) {
for(int j = 1;j <= c;j++) {
cin>>b;
if(b == '#') {
k[i][j] = 1;
continue;
}
k[i][j] = 0;
}
}
for(int i = 2;i <= r;i++) {
for(int j = 2;j <= c;j++) {
int ans = 0;
if(k[i - 1][j - 1]) {
ans++;
}
if(k[i - 1][j]) {
ans++;
}
if(k[i][j - 1]) {
ans++;
}
if(k[i][j]) {
ans++;
}
if(ans == 3) {
printf("Bad placement.\n");
return 0;
}
}
}
int ans = 0;
for(int i = 1;i <= r;i++) {
for(int j = 1;j <= c;j++) {
if(k[i][j]) {
ans++;
queue<int>x,y;
x.push(i);
y.push(j);
while(!x.empty()) {
int x2 = x.front();
int y2 = y.front();
if(k[x2][y2 + 1]) {
x.push(x2);
y.push(y2 + 1);
k[x2][y2 + 1] = 0;
}
if(k[x2 + 1][y2]) {
x.push(x2 + 1);
y.push(y2);
k[x2 + 1][y2] = 0;
}
x.pop();
y.pop();
}
}
}
}
printf("There are %d ships.",ans);
return 0;
}