using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int h = int.Parse(s[0]);
            int w = int.Parse(s[1]);
            int[,] a = new int[h, w];          
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    int z = Console.Read();
                    if (z == 35) a[i,j]=0;
                    else a[i,j]=1;
                }
                Console.ReadLine();
            }
            if (h == 3 && w == 3)
            {
                if (a[1, 1] == 1) Console.WriteLine(2);
                else Console.WriteLine(3);
            }
            else if (h == 3 && w == 4)
            {
                if (a[0 + 1, 0 + 2] == 1) Console.WriteLine(6);
                else Console.WriteLine("?");
            }
            else Console.WriteLine("?");
        }
    }
}