#include <iostream>
using namespace std;

int main()
{

int h, w;
int i = 0, j = 0, t = 0; 
int brojac1 = 0, brojac3 = 0;
cin>> h;
cin>> w;


char polje[h][w];

for(i=0;i<h; i++)
{
    for(j=0;j<w;j++)
    {
    cin>> char[i][j];
         
    }


}

for(i = 0; i<h; i++)
{


    for(j=0; j<w; j++)
    {
    if(i==j)
    {
        if(char[i][j]== "#")
        {

        brojac1 = brojac1 + 1;         
             
        }

    }
    }
}
if(h%2 == w%2)
{
   if(brojac1 == 0)
   {
       t = 3;
   }

}
else
{
    if(brojac1== 0)
    {
      t=5;
    }
}

cout<< t;
}