#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> fonk(vector<vector<char>>& vec, int r, int c,
                         vector<vector<bool>> visited, int count,
                         vector<vector<int>>& paths) {
  if (paths[r][c])
    paths[r][c] = min(count, paths[r][c]);
  else
    paths[r][c] = count;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      if ((i == 0 || j == 0) && !(i == 0 && j == 0))
        if (r + i >= 0 && r + i < vec.size() && c + j >= 0 &&
            c + j < vec[0].size() && !visited[r + i][c + j]) {
          visited[r + i][c + j] = true;
          fonk(vec, r + i, c + j, visited, count + 1, paths);
          visited[r + i][c + j] = false;
        }
    }
  }
  return paths;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w;
  cin >> h >> w;
  vector<vector<char>> vec(h, vector<char>(w));
  vector<vector<bool>> visited(h, vector<bool>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> vec[i][j];
      if (vec[i][j] == '.')
        visited[i][j] = 0;
      else
        visited[i][j] = 1;
    }
  }
  int res = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (vec[i][j] != '#') {
        visited[i][j] = true;
        vector<vector<int>> paths(h, vector<int>(w, 0));
        fonk(vec, i, j, visited, 0, paths);
        for (auto x : paths) {
          for (auto y : x) {
            res = max(res, y);
          }
        }
        visited[i][j] = false;
      }
    }
  }
  cout << res;
  return 0;
}
