#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> s(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> s[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if ('#' == s[i][j]) {
        continue;
      }
      queue<pair<int, int>> q;
      vector<vector<int>> dist(H + 5, vector<int>(W + 5, -1));
      vector<vector<pair<int, int>>> prev(H + 5, vector<pair<int, int>>(W + 5));
      dist[i][j] = 0;
      vector<int> ver = {0, -1, 0, 1};
      vector<int> hor = {-1, 0, 1, 0};
      q.push(make_pair(i, j));
      while (!q.empty()) {
        pair<int, int> temp = q.front();
        q.pop();
        for (int k = 0; k < 4; k++) {
          int tempi = temp.first + ver[k];
          int tempj = temp.second + hor[k];
          if (tempi < 0 || tempi >= H || tempj < 0 || tempj >= W) {
            continue;
          }
          if (s[tempi][tempj] != '.') {
            continue;
          }
          if (dist[tempi][tempj] > 0) {
            continue;
          }
          q.emplace(tempi, tempj);
          dist[tempi][tempj] = dist[temp.first][temp.second] + 1;
          ans = max(ans, dist[tempi][tempj]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
