#include <bits/stdc++.h>
using namespace std;
vector<int> xd{-1, 1, 0, 0};
vector<int> yd{0, 0, -1, 1};
int X, Y;
int bfs(vector<string>& b, int x, int y) {
  vector<vector<int>> ds(Y, vector<int>(X, 50000));
  queue<pair<int, int>> st;
  int maxD = 0;
  st.push(make_pair(x, y));
  ds[y][x] = 0;
  while (!st.empty()) {
    auto now = st.front();
    st.pop();
    int nx = now.first;
    int ny = now.second;
    for (int d = 0; d < 4; d++) {
      int tx = now.first + xd[d];
      int ty = now.second + yd[d];
      if (tx < 0 || tx >= X || ty < 0 || ty >= Y || b[ty][tx] == '#') {
        continue;
      }
      if (ds[ty][tx] <= ds[ny][nx] + 1) {
        continue;
      }
      ds[ty][tx] = ds[ny][nx] + 1;
      st.push(make_pair(tx, ty));
    }
  }
  for (int y = 0; y < Y; y++) {
    for (int x = 0; x < X; x++) {
      if (b[y][x] == '#' || ds[y][x] == 50000) {
        continue;
      }
      maxD = max(maxD, ds[y][x]);
    }
  }
  return maxD;
}
int main() {
  cin >> Y >> X;
  vector<string> b(Y);
  for (int y = 0; y < Y; y++) {
    cin >> b[y];
  }
  int maxD = 0;
  for (int y = 0; y < Y; y++) {
    for (int x = 0; x < X; x++) {
      maxD = max(maxD, bfs(b, x, y));
    }
  }
  cout << maxD;
  return 0;
}
