#include<bits/stdc++.h>
#define pp pair<int,int>
#define f first
#define s second
using namespace std;
char b[1000][1000];
queue<pp>a;
int dx[5]= {0,-1,1,0,0};
int dy[5]= {0,0,0,-1,1};
bool check(int i,int j) {
int w=0;
if(b[i][j]=='#')w++;
if(b[i][j+1]=='#')w++;
if(b[i+1][j]=='#')w++;
if(b[i+1][j+1]=='#')w++;
return w==3;
}
void bfs(int i,int j) {
pair<int,int>c;
c.f=i,c.s=j;
b[i][j]='.';
a.push(c);
while(!a.empty()) {
pair<int,int>e=a.front();
for(int i=1; i<=4; i++) {
pair<int,int>d=e;
d.f+=dx[i];
d.s+=dy[i];
if(b[d.f][d.s]=='.')continue;
b[d.f][d.s]='.';
a.push(d);
}
a.pop();
}
}
int main() {
int r,c,o=0;
cin>>r>>c;
for(int i=1; i<=r; i++)
for(int j=1; j<=c; j++)
cin>>b[i][j];
for(int i=1; i<=r; i++)
for(int j=1; j<=c; j++)
if(check(i,j)) {
cout<<"Bad placement."<<endl;
return 0;
}
for(int i=1; i<=r; i++)
for(int j=1; j<=c; j++) {
if(b[i][j]!='.') {
bfs(i,j);
o++;
}
}
cout<<"There are "<<o<<" ships.";
}