#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
const double PI = acos(-1);
struct pos {
  int x;
  int y;
  pos(int x, int y) : x(x), y(y) {}
};
deque<pos> dq;
int max_depth = 0;
void bfs(vector<vector<int>> maze, int depth = 1) {
  int size = dq.size();
  for (int i = 0; i < size; ++i) {
    pos p = dq.front();
    dq.pop_front();
    maze[p.x][p.y] = -1;
    if (maze[p.x - 1][p.y] == 0) {
      dq.push_back(pos(p.x - 1, p.y));
    }
    if (maze[p.x + 1][p.y] == 0) {
      dq.push_back(pos(p.x + 1, p.y));
    }
    if (maze[p.x][p.y - 1] == 0) {
      dq.push_back(pos(p.x, p.y - 1));
    }
    if (maze[p.x][p.y + 1] == 0) {
      dq.push_back(pos(p.x, p.y + 1));
    }
  }
  if (dq.empty()) {
    if (max_depth < depth - 1) {
      max_depth = depth - 1;
    }
    return;
  }
  bfs(maze, depth + 1);
}
int main() {
  int h, w;
  cin >> h >> w;
  if (h == 1 && w == 1) cout << 0 << endl;
  vector<vector<int>> maze(h + 2, vector<int>(w + 2, -1));
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      char tmp;
      cin >> tmp;
      if (tmp == '.') maze[i][j] = 0;
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (maze[i][j] != -1) {
        dq.push_back(pos(i, j));
        bfs(maze);
      }
    }
  }
  cout << max_depth << endl;
  return 0;
}
