Problem: Constraints

* H is an integer between 2 and 50 (inclusive).
* W is an integer between 2 and 50 (inclusive).
* s_{i, j} is `.` or `#` (1 \leq i \leq H, 1 \leq j \leq W).
* s_{1, 1} and s_{H, W} are `.`.

Input

Input is given from Standard Input in the following format:


H W
s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W}
s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W}
:   :
s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}


Output

Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed.

Examples

Input

3 3
..#
#..
...


Output

2


Input

3 3
..#
..
...


Output

2


Input

10 37
.....................................
...#...####...####..###...###...###..
..#.#..#...#.##....#...#.#...#.#...#.
..#.#..#...#.#.....#...#.#...#.#...#.
.#...#.#..##.#.....#...#.#.###.#.###.
.#####.####..#.....#...#..##....##...
.#...#.#...#.#.....#...#.#...#.#...#.
.#...#.#...#.##....#...#.#...#.#...#.
.#...#.####...####..###...###...###..
.....................................


Output

209

Solution (in CPP):

Solution:
#include<iostream>
#include<queue>
using namespace std;

int main() {
  int H, W; cin >> H >> W;
  int N = H*W;
  int A[N]; string str;
  int white_num = 0;
  for (int i = 0; i < H; i++) {
    cin >> str;
    for (int j = 0; j < W; j++) {
      white_num += A[i*W+j] = (str[j] == '.');
    }
  }
  queue<pair<int, int>> Q; Q.push(make_pair(0, 1));
  bool visited[N]; for (int i = 0; i < N; i++) visited[i] = false;
  visited[0] = true;
  int score = -1;
  while (!Q.empty()) {
    auto front = Q.front(); Q.pop();
    int u = front.first, d = front.second;
    if (u == H*W-1) { score = white_num-d; break; }
    vector<int> e;
    if (u >= W) e.push_back(u-W);
    if (u % W > 0) e.push_back(u-1);
    if (u % W < W-1) e.push_back(u+1);
    if (u / W < H-1) e.push_back(u+W);
    for (int v : e) {
      if (A[v] && !visited[v]) {
        visited[v] = true;
        Q.push(make_pair(v, d+1));
      }
    }
  }
  cout << score << endl;
}