Problem: Example

Input

2 2
..
..


Output

Second

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int h,w,dp[22][22][22][22];
string s[55];
int dfs(int ul,int ur,int dl,int dr){
  if(ul>dl||ur>dr)return 0;
  if(dp[ul][ur][dl][dr]!=-1)return dp[ul][ur][dl][dr];
  set<int>st;
  r(i,ul,dl+1){
    r(j,ur,dr+1){
      if(s[i][j]=='X')continue;
      int a,b,c,d;
      a=dfs(ul,ur,i-1,j-1);
      b=dfs(ul,j+1,i-1,dr);
      c=dfs(i+1,ur,dl,j-1);
      d=dfs(i+1,j+1,dl,dr);
      st.insert(a^b^c^d);
    }
  }
  int res=0;
  while(st.count(res))res++;
  return dp[ul][ur][dl][dr]=res;
}
int main(){
  memset(dp,-1,sizeof(dp));
  cin>>h>>w;
  r(i,0,h)cin>>s[i];
  cout<<(dfs(0,0,h-1,w-1)?"First":"Second")<<endl;
}