#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  int lastNo = 0;
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++) {
      cin >> S[i][j];
    }
  int MAX = 0;
  for (int lastX = 0; lastX < (int)(H); lastX++)
    for (int lastY = 0; lastY < (int)(W); lastY++) {
      bool flag = true;
      vector<vector<int>> Ldist(H, vector<int>(W));
      while (flag) {
        vector<vector<int>> dist(H, vector<int>(W));
        dist = Ldist;
        dist[lastX][lastY] = 1;
        for (int i = 0; i < (int)(H); i++)
          for (int j = 0; j < (int)(W); j++) {
            int Ndist = dist[i][j];
            if (Ndist != 0) {
              int Ndist = dist[i][j];
              if (i != 0) {
                if (S[i - 1][j] == '.' && dist[i - 1][j] == 0)
                  dist[i - 1][j] += Ndist + 1;
              }
              if (i != H - 1) {
                if (S[i + 1][j] == '.' && dist[i + 1][j] == 0)
                  dist[i + 1][j] += Ndist + 1;
              }
              if (j != 0) {
                if (S[i][j - 1] == '.' && dist[i][j - 1] == 0)
                  dist[i][j - 1] += Ndist + 1;
              }
              if (j != W - 1) {
                if (S[i][j + 1] == '.' && dist[i][j + 1] == 0)
                  dist[i][j + 1] += Ndist + 1;
              }
            }
            MAX = max(MAX, Ndist - 1);
          }
        flag = Ldist != dist;
        Ldist = dist;
      }
    }
  cout << MAX << endl;
  return 0;
}
