#include <bits/stdc++.h>
using namespace std;
int H, W;
int main() {
  cin >> H >> W;
  vector<string> fi(H);
  for (int i = 0; i < H; i++) {
    cin >> fi[i];
  }
  vector<int> ans;
  int dx[4] = {0, 0, 1, -1};
  int dy[4] = {1, -1, 0, 0};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      for (int k = 0; k < H; k++) {
        for (int l = 0; l < W; l++) {
          vector<vector<int>> dist(H, vector<int>(W, -1));
          using pir = pair<int, int>;
          queue<pir> que;
          dist[i][j] = 0;
          que.push(pir(i, j));
          while (!que.empty()) {
            auto v = que.front();
            que.pop();
            for (int i = 0; i < 4; i++) {
              int nx = v.second + dx[i];
              int ny = v.first + dy[i];
              if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
              if (fi[ny][nx] == '#') continue;
              if (dist[ny][nx] != -1) continue;
              dist[ny][nx] = dist[v.first][v.second] + 1;
              que.push(pir(ny, nx));
            }
          }
          ans.push_back(dist[k][l]);
        }
      }
    }
  }
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  cout << ans[0] << endl;
}
