#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<algorithm>
#define ll long long
int hz[1005][1005],ans,n,m;
void dfs(int x,int y){
if(x<1||x>n||y<1||y>m||hz[x][y]==0){
return ;
}
hz[x][y]=0;
dfs(x+1,y);
dfs(x-1,y);
dfs(x,y-1);
dfs(x,y+1);
}
using namespace std;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
string s;
cin>>s;
for(int j=0;j<m;j++){
if(s[j]=='.') hz[i][j+1]=0;
else hz[i][j+1]=1;
}
}
if(n==1&&m==1){
if(hz[1][1]==1) cout<<"There are "<<1<<" ships.";
return 0;
}
if(n==1){
int cnt=0;
for(int i=1;i<=m;i++){
if(hz[1][i]==1&&hz[i-1][1]){
cnt++;
}
}
cout<<"There are "<<cnt<<" ships.";
return 0;
}
if(m==1){
int cnt=0;
for(int i=1;i<=n;i++){
if(hz[i][1]==1&&hz[1][i-1]){
cnt++;
}
}
cout<<"There are "<<cnt<<" ships.";
return 0;
}
int cnt1=0;
for(int i=1;i<n;i++){
for(int j=1;j<m;j++){
int cnt=hz[i][j]+hz[i][j+1]+hz[i+1][j]+hz[i+1][j+1];
if(cnt==3){
cnt1++;
if(hz[i][j]+hz[i+1][j]==1){
for(int k=i;k<=n;k++){
if(hz[k][j+1]==1){
cnt1--;
break;
}
}
}
else if(hz[i][j+1]+hz[i+1][j+1]==1){
for(int k=i;k<=n;k++){
if(hz[k][j]==1){
cnt1--;
break;
}
}
}
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(hz[i][j]!=0){
dfs(i,j);
ans++;
}
}
}
if(ans-cnt1==0) cout<<"Bad placement.";
cout<<"There are "<<ans-cnt1<<" ships.";
return 0;
}