#include<bits/stdc++.h>
using namespace std;
int n,m,a[1001][1001][3],cnt=0;
bool f=false;
void dfs(int x,int y){
if(f) return;
int sx=x,sy=y,ex=x,ey=y;
while(a[sx][y][1]==1&&sx<=n) sx++;
while(a[x][sy][1]==1&&sy<=m) sy++;
while(a[ex][y][1]==1&&ex>=1) ex--;
while(a[x][ey][1]==1&&ey>=1) ey--;
for(int i=sx+1;i<ex&&!f;i++){
for(int j=sy+1;j<ey&&!f;j++){
if(!a[i][j][1]){
cout << "Bad placement.";
f=true;
}
}
}
if(f)return;
else if(!a[x][y][2]) cnt++;
for(int i=sx+1;i<ex&&!f;i++){
for(int j=sy+1;j<ey&&!f;j++){
a[i][j][2]=1;
}
}
return;
}
int main(){
cin >> n >> m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char c;
cin >> c;
if(c=='#') a[i][j][1]=1;
else a[i][j][1]=0;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j][1]){
dfs(i,j);
a[i][j][2]=1;
}
}
}
if(!f) cout << "There are " << cnt << " ships.";
return 0;
}