#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> maze;
  for (int i = 0; i < (int)(h); i++) {
    string str;
    cin >> str;
    maze.push_back(str);
  }
  int biggest = 0;
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      if (maze[i][j] == '#') continue;
      vector<string> mazeCopy = maze;
      queue<vector<int>> que;
      vector<int> tmp = {j, i, 0};
      que.push(tmp);
      int biggestInThisPattern = 0;
      while (!que.empty()) {
        int x = que.front()[0];
        int y = que.front()[1];
        int cnt = que.front()[2];
        biggestInThisPattern = max(cnt, biggestInThisPattern);
        que.pop();
        for (int dx = -1, dy = 0, i = 0; i < 4;
             dx += dy, dy = dx - dy, dx = dy - dx, ++i) {
          if (0 <= x + dx && x + dx < w && 0 <= y + dy && y + dy < h &&
              mazeCopy[y + dy][x + dx] == '.') {
            mazeCopy[y + dy][x + dx] = '#';
            vector<int> vec = {x + dx, y + dy, cnt + 1};
            que.push(vec);
          }
        }
      }
      biggest = max(biggest, biggestInThisPattern);
    }
  }
  cout << biggest << endl;
  return 0;
}
