#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> grid(H + 2, vector<char>(W + 2, '#'));
  string S;
  for (int i = (int)1; i < (int)H + 1; i++) {
    cin >> S;
    for (int j = (int)1; j < (int)W + 1; j++) {
      grid[i][j] = S[j - 1];
    }
  }
  int INF = (int)1e9 + 7;
  vector<vector<int>> dist(H * W, vector<int>(H * W, INF));
  vector<vector<int>> list(H * W);
  int x, y, v;
  for (int i = (int)0; i < (int)H; i++) {
    x = i + 1;
    for (int j = (int)0; j < (int)W; j++) {
      y = j + 1;
      v = i * H + j;
      if (grid[x][y] == '#') {
        continue;
      }
      if (grid[x][y - 1] == '.') {
        list[v].push_back(v - 1);
        list[v - 1].push_back(v);
        dist[v][v] = 0;
        dist[v][v - 1] = 1;
        dist[v - 1][v] = 1;
      }
      if (grid[x - 1][y] == '.') {
        list[v].push_back(v - H);
        list[v - H].push_back(v);
        dist[v][v] = 0;
        dist[v][v - H] = 1;
        dist[v - H][v] = 1;
      }
      if (grid[x][y + 1] == '.') {
        list[v].push_back(v + 1);
        list[v + 1].push_back(v);
        dist[v][v] = 0;
        dist[v][v + 1] = 1;
        dist[v + 1][v] = 1;
      }
      if (grid[x + 1][y] == '.') {
        list[v].push_back(v + H);
        list[v + H].push_back(v);
        dist[v][v] = 0;
        dist[v][v + H] = 1;
        dist[v + H][v] = 1;
      }
    }
  }
  for (int i = (int)0; i < (int)H * W; i++) {
    for (int j = (int)0; j < (int)H * W; j++) {
      for (int k = (int)0; k < (int)H * W; k++) {
        chmin(dist[j][k], dist[j][i] + dist[i][k]);
      }
    }
  }
  int ans = 0;
  for (int i = (int)0; i < (int)H * W; i++) {
    for (int j = (int)0; j < (int)H * W; j++) {
      if (dist[i][j] == INF) {
        continue;
      } else {
        ans = max(ans, dist[i][j]);
      }
    }
  }
  cout << ans << endl;
};
