#include <bits/stdc++.h>
constexpr long long mop = 1000000007;
constexpr long long mop2 = 998244353;
using namespace std;
struct Point {
  long long x, y;
};
void bfs(Point start, vector<vector<long long>>& distance,
         const vector<vector<bool>> maze, const long long h,
         const long long w) {
  queue<Point> Q;
  Q.push(start);
  distance[start.x][start.y] = 0;
  while (!Q.empty()) {
    Point now = Q.front();
    long long nowDistance = distance[now.x][now.y];
    Q.pop();
    Point pt1, pt2, pt3, pt4;
    pt1 = pt2 = pt3 = pt4 = now;
    pt1.x++;
    pt2.y++;
    pt3.x--;
    pt4.y--;
    vector<Point> nextPointList;
    nextPointList.push_back(pt1);
    nextPointList.push_back(pt2);
    nextPointList.push_back(pt3);
    nextPointList.push_back(pt4);
    for (Point next : nextPointList) {
      if (0 <= next.x && next.x < h && 0 <= next.y && next.y < w &&
          maze[next.x][next.y] == true && distance[next.x][next.y] == -1) {
        distance[next.x][next.y] = nowDistance + 1;
        Q.push(next);
      }
    }
  }
}
int main() {
  long long h, w;
  cin >> h >> w;
  vector<vector<bool>> maze;
  vector<vector<long long>> distance;
  maze.resize(h);
  distance.resize(h);
  Point st;
  for (long long i = 0; i < h; i++) {
    maze[i].resize(w);
    distance[i].resize(w);
    string s;
    cin >> s;
    for (long long j = 0; j < w; j++) {
      distance[i][j] = -1;
      if (s[j] == '.') {
        maze[i][j] = true;
        st.x = i;
        st.y = j;
      }
    }
  }
  bfs(st, distance, maze, h, w);
  long long maxDistance = -1;
  Point mdp;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (distance[i][j] > maxDistance) {
        maxDistance = distance[i][j];
        mdp.x = i;
        mdp.y = j;
      }
    }
  }
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      distance[i][j] = -1;
    }
  }
  bfs(mdp, distance, maze, h, w);
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (distance[i][j] > maxDistance) {
        maxDistance = distance[i][j];
      }
    }
  }
  cout << maxDistance << endl;
}
