#include <bits/stdc++.h>
using namespace std;
int H, W;
bool visited[1000][1000];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
vector<string> m;
int main(void) {
  int num = 0;
  cin >> H >> W;
  for (int i = 0; i < (H); ++i) {
    string st;
    cin >> st;
    m.push_back(st);
  }
  int maxdist = 0;
  for (int starth = 0; starth < (H); ++starth) {
    for (int startw = 0; startw < (W); ++startw) {
      memset(visited, false, sizeof(visited));
      queue<int> queueX;
      queue<int> queueY;
      queue<int> dist;
      queueX.push(startw);
      queueY.push(starth);
      dist.push(0);
      visited[starth][startw] = true;
      while (!queueX.empty()) {
        int x = queueX.front();
        int y = queueY.front();
        int distance = dist.front();
        if (distance > maxdist) maxdist = distance;
        queueX.pop();
        queueY.pop();
        dist.pop();
        for (int i = 0; i < (4); ++i) {
          int nx = x + dx[i];
          int ny = y + dy[i];
          if (nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
          if (visited[ny][nx]) continue;
          if (m[ny][nx] == '#') continue;
          visited[ny][nx] = true;
          queueX.push(nx);
          queueY.push(ny);
          dist.push(distance + 1);
        }
      }
    }
  }
  cout << maxdist << endl;
}
