#include <bits/stdc++.h>
int main() {
  int h, w;
  std::cin >> h >> w;
  std::vector<char> s;
  s.resize(static_cast<size_t>(h * w));
  for (int _i = 0; _i < (h * w); _i++) {
    char _s;
    std::cin >> _s;
    s[_i] = _s;
  }
  if (h == 1 && w == 1) {
    std::cout << 0;
    return 0;
  }
  if (h == 1 || w == 1) {
    int start = 0;
    int m = std::max(h, w);
    while (s[start] == '#') {
      start++;
      if (start == m) {
        std::cout << 0;
        return 0;
      }
    }
    if (start == (m - 1)) {
      std::cout << 0;
      return 0;
    }
    int c = 0;
    start++;
    while (s[start] == '.') {
      c++;
      start++;
      if (start == m) {
        std::cout << c;
        return 0;
      }
    }
    std::cout << c;
    return 0;
  }
  int start = (h / 2) * w + (w / 2);
  int _start = start;
  while (s[start] == '#') {
    start--;
    if (start < 0) break;
  }
  if (start < 0) {
    start = _start + 1;
    while (s[start] == '#') {
      start++;
      if (start >= (h * w)) break;
    }
  }
  std::vector<int> ins(h * w, -1);
  ins[start] = 0;
  std::list<int> backup;
  while (1) {
    bool isok = false;
    int upidx = start - w;
    if (upidx >= 0) {
      if ((s[upidx] == '.') && (ins[upidx] < 0)) {
        backup.push_back(upidx);
        ins[upidx] = ins[start] + 1;
        isok = true;
      }
    }
    int leftidx = start - 1;
    if ((leftidx % w) != (w - 1)) {
      if ((s[leftidx] == '.') && (ins[leftidx] < 0)) {
        backup.push_back(leftidx);
        ins[leftidx] = ins[start] + 1;
        isok = true;
      }
    }
    int downidx = start + w;
    if (downidx < (w * h)) {
      if ((s[downidx] == '.') && (ins[downidx] < 0)) {
        backup.push_back(downidx);
        ins[downidx] = ins[start] + 1;
        isok = true;
      }
    }
    int rightidx = start + 1;
    if ((rightidx % w) != 0) {
      if ((s[rightidx] == '.') && (ins[rightidx] < 0)) {
        backup.push_back(rightidx);
        ins[rightidx] = ins[start] + 1;
        isok = true;
      }
    }
    if (isok == false) {
      if (backup.empty()) {
        break;
      }
    }
    start = backup.back();
    backup.pop_back();
  }
  auto max_itr = std::max_element(ins.cbegin(), ins.cend());
  int max = *max_itr;
  ins.erase(max_itr);
  auto max_itr2 = std::max_element(ins.cbegin(), ins.cend());
  max += *max_itr2;
  std::cout << max;
  return 0;
}
