#include <bits/stdc++.h>
using namespace std;
vector<int> x = {0, 1, 0, -1};
vector<int> y = {1, 0, -1, 0};
queue<vector<int>> q;
int main() {
  int H, W, length, maxLen;
  string s;
  cin >> H >> W;
  length = maxLen = 0;
  vector<vector<int>> map(H, vector<int>(W, 0));
  queue<vector<int>> q;
  for (int i = (int)(0); i < (int)(H); i++) {
    cin >> s;
    for (int j = (int)(0); j < (int)(s.size()); j++) {
      if (s[j] == '.') {
        map[i][j] = 1;
      }
    }
  }
  for (int s = (int)(0); s < (int)(H * W); s++) {
    int si = s / W;
    int sj = s % W;
    if (map[si][sj] == 1) {
      vector<vector<int>> memo(H, vector<int>(W, 0));
      memo[si][sj] = 1;
      length = 0;
      q.push({si, sj});
      while (!q.empty()) {
        vector<int> cur = q.front();
        q.pop();
        for (int i = (int)(0); i < (int)(4); i++) {
          int next_y = cur[0] + y[i];
          int next_x = cur[1] + x[i];
          if (next_y >= 0 && next_x >= 0 && next_y < H && next_x < W) {
            if (map[next_y][next_x] == 1 && !memo[next_y][next_x]) {
              q.push({next_y, next_x});
              memo[next_y][next_x] = memo[cur[0]][cur[1]] + 1;
            }
          }
        }
      }
      for (int i = (int)(0); i < (int)(H); i++) {
        length = max(length, *max_element(memo[i].begin(), memo[i].end())) - 1;
      }
    }
    if (maxLen < length) {
      maxLen = length;
    }
  }
  cout << maxLen << endl;
}
