#include <bits/stdc++.h>

using namespace std;

int N,M,Tabla[10000],[10000];
int main()
{
    cin>>N>>M;
    
    for(int n=1; n<=N; n++)
    {
        for(int m=1; m<=M; m++)
        {
            cin>>Tabla[n][m];
        }
    }
    
    if(N<=5 and M<=5)
    {
        if(N==3 and M==5 and Tabla[2][3]==46)cout<<6<<endl;
        
        if(N==5 and M==3 and Tabla[3][2]==46)cout<<6<<endl;
        
        if(N==5 and M==5 and Tabla[2][2]==46 and Tabla[3][3]==46 and Tabla[4][4]==46)cout<<3<<endl;
        
    }

    return 0;
}