#include <bits/stdc++.h>
using namespace std;
char field[500];
inline int isIn(int w, int h, int x, int y) {
  if (x < 0 || x >= w) return 0;
  if (y < 0 || y >= h) return 0;
  return 1;
}
pair<int, int> bfs(int w, int h, int x, int y) {
  int dist[500];
  deque<int> dq;
  int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
  int mxDist = -1, mxPos;
  for (int i = 0; i < 500; i++) dist[i] = -1;
  dq.push_back(x + y * w);
  dist[x + y * w] = 0;
  while (dq.size()) {
    x = dq[0] % w;
    y = dq[0] / w;
    dq.pop_front();
    for (int i = 0; i < 4; i++) {
      int xx, yy;
      xx = x + dx[i];
      yy = y + dy[i];
      if (isIn(w, h, xx, yy) == 0) continue;
      if (field[(xx) + (yy)*w] == '#' || dist[(xx) + (yy)*w] >= 0) continue;
      dist[(xx) + (yy)*w] = dist[(x) + (y)*w] + 1;
      if (dist[(xx) + (yy)*w] > mxDist) {
        mxDist = dist[(xx) + (yy)*w];
        mxPos = xx + yy * w;
      }
      dq.push_back(xx + yy * w);
    }
  }
  return make_pair(mxPos, mxDist);
}
int main(void) {
  int h, w, farest, st;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    char buf[30];
    cin >> buf;
    for (int j = 0; j < w; j++) {
      field[(j) + (i)*w] = buf[j];
      if (buf[j] != '#') st = j + i * w;
    }
  }
  farest = bfs(w, h, 0, 0).first;
  cout << bfs(w, h, farest % w, farest / w).second << endl;
  return 0;
}
