#include<iostream>
using namespace std;
char a[1010][1010] = {};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
int dy[8] = {1,0,-1,0,1,-1,1,-1};
int n,m;
void dfs(int x,int y)
{
a[x][y] = '.';
for(int i = 0;i<=3;i++)
{
int nx = x+dx[i],ny = y+dy[i];
if(nx<0 || ny<0 || nx>n || ny>m || a[nx][ny]!='#')continue;
dfs(nx,ny);
}
}
int main()
{
cin>>n>>m;
for(int i = 1;i<=n;i++)
for(int j =1;j<=m;j++)
cin>>a[i][j];
int cnt = 0;
for(int i = 1;i<=n;i++)
for(int j = 1;j<=m;j++)
{
if(a[i][j] == '.')continue;
int tmp = 0;
for(int k = 0;k<8;k++)tmp+=(a[i+dx[k]][j+dy[k]] == '.');
if(tmp == 1)
{
cout<<"Bad placement.";
return 0;
}
}
for(int i = 1;i<=n;i++)
for(int j = 1;j<=m;j++)
{
if(a[i][j] == '.')continue;
cnt++;
dfs(i,j);
}
cout<<"There are ";
cout<<cnt;
cout<<" ships." ;
}