#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  int maize[H + 2][W + 2], chain[H + 2][W + 2], state[H + 2][W + 2];
  long long ans[H + 2][W + 2];
  for (int i = 0; i < H + 2; i++) {
    for (int l = 0; l < W + 2; l++) {
      maize[i][l] = 0;
      chain[i][l] = -1;
      state[i][l] = 1;
      ans[i][l] = 0;
    }
  }
  string tmp;
  for (int i = 0; i < H; i++) {
    cin >> tmp;
    for (int l = 0; l < W; l++) {
      if (tmp[l] == '.') {
        maize[i + 1][l + 1] = 1;
        state[i + 1][l + 1] = 0;
      } else {
        maize[i + 1][l + 1] = 0;
      }
    }
  }
  int h = 0, w = 0;
  bool ck = false;
  for (int i = 0; i < H; i++) {
    for (int l = 0; l < W; l++) {
      int cnt = 0;
      if (maize[i + 1][l + 1] == 1) {
        if (maize[i][l + 1] == 1) {
          cnt++;
        }
        if (maize[i + 1][l] == 1) {
          cnt++;
        }
        if (maize[i + 2][l + 1] == 1) {
          cnt++;
        }
        if (maize[i + 1][l + 2] == 1) {
          cnt++;
        }
      }
      chain[i + 1][l + 1] = cnt;
      if (cnt == 1) {
        h = i;
        w = l;
        ck = true;
      }
      if (!ck) {
        h = i;
        w = l;
      }
    }
  }
  queue<pair<int, int> > que;
  que.push(make_pair(h, w));
  ans[h + 1][w + 1] = 0;
  state[h + 1][w + 1] = 1;
  int tmph, tmpw;
  while (true) {
    bool next = false;
    if (maize[h][w + 1] == 1 && state[h][w + 1] == 0) {
      next = true;
      state[h][w + 1] = 1;
      tmph = h - 1;
      tmpw = w;
      ans[h][w + 1] = ans[h + 1][w + 1] + 1;
    } else if (maize[h + 1][w] == 1 && state[h + 1][w] == 0) {
      next = true;
      state[h + 1][w] = 1;
      tmph = h;
      tmpw = w - 1;
      ans[h + 1][w] = ans[h + 1][w + 1] + 1;
    } else if (maize[h + 2][w + 1] == 1 && state[h + 2][w + 1] == 0) {
      next = true;
      state[h + 2][w + 1] = 1;
      tmph = h + 1;
      tmpw = w;
      ans[h + 2][w + 1] = ans[h + 1][w + 1] + 1;
    } else if (maize[h + 1][w + 2] == 1 && state[h + 1][w + 2] == 0) {
      next = true;
      state[h + 1][w + 2] = 1;
      tmph = h;
      tmpw = w + 1;
      ans[h + 1][w + 2] = ans[h + 1][w + 1] + 1;
    }
    if (next) {
      que.push(make_pair(tmph, tmpw));
    } else if (que.empty()) {
      break;
    } else {
      pair<int, int> tmp = que.front();
      que.pop();
      h = tmp.first;
      w = tmp.second;
    }
  }
  long long max = 0;
  for (int i = 0; i < H + 1; i++) {
    for (int l = 0; l < W + 1; l++) {
      if (max < ans[i][l]) {
        max = ans[i][l];
      }
    }
  }
  cout << max << endl;
  return 0;
}
