#include <iostream>
#include <string>
#include <tuple>
#include <queue>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  string s[h];
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      bool b[h][w] = {};
      queue<tuple<int, int, int>> q;
      b[i][j] = true;
      q.push(make_tuple(i, j, 0));
      while (!q.empty()) {
        int& x = get<0>(q.front());
        int& y = get<1>(q.front());
        int& c = get<2>(q.front());
        q.pop();
        ans = max(ans, c);
        if (x != 0 && !b[x-1][y] && s[x-1][y] == '.') {
          b[x-1][y] = true;
          q.push(make_tuple(x-1, y, c+1));
        }
        if (x != h-1 && !b[x+1][y] && s[x+1][y] == '.') {
          b[x+1][y] = true;
          q.push(make_tuple(x+1, y, c+1));
        }
        if (y != 0 && !b[x][y-1] && s[x][y-1] == '.') {
          b[x][y-1] = true;
          q.push(make_tuple(x, y-1, c+1));
        }
        if (y != w-1 && !b[x][y+1] && s[x][y+1] == '.') {
          b[x][y+1] = true;
          q.push(make_tuple(x, y+1, c+1));
        }
      }
    }
  }
  cout << ans << endl;
}