Problem: Example

Input

2 2
..
..


Output

Second

Solution (in CPP):

Solution:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

int mex(vector<int> &v) {
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()),v.end());
	rep(i, v.size()) {
		if (i != v[i])return i;
	}
	return v.size();
}

bool used[20][20][20][20];
int win[20][20][20][20];
char mp[20][20];

int dfs(int lx, int ly, int rx, int ry) {
	if (lx > rx || ly > ry)return 0;
	if (used[lx][ly][rx][ry])return win[lx][ly][rx][ry];
	used[lx][ly][rx][ry] = true;
	vector<int> v;
	Rep1(i, lx, rx) {
		Rep1(j, ly, ry) {
			if (mp[i][j] == 'X')continue;
			int x = 0;
			x ^= dfs(lx, ly, i - 1, j - 1);
			x ^= dfs(lx, j + 1, i - 1, ry);
			x ^= dfs(i + 1, ly, rx, j - 1);
			x ^= dfs(i + 1, j + 1, rx, ry);
			v.push_back(x);
		}
	}
	return win[lx][ly][rx][ry] = mex(v);
}
int h, w;
void solve() {
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			cin >> mp[i][j];
		}
	}
	int u = dfs(0, 0, h - 1, w - 1);
	if (u == 0) {
		cout << "Second" << endl;
	}
	else {
		cout << "First" << endl;
	}
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	solve();
	//stop
	return 0;
}