#include <bits/stdc++.h>
using namespace std;
vector<vector<bool> > mpCopy(vector<vector<bool> > mp) {
  vector<vector<bool> > newMp(mp.size(), vector<bool>(mp[0].size()));
  for (int i = 0; i < mp.size(); i++) {
    for (int j = 0; j < mp[i].size(); j++) {
      newMp[i][j] = mp[i][j];
    }
  }
  return newMp;
}
void solver() {
  int h, w;
  cin >> h >> w;
  vector<vector<bool> > mp(h + 2, vector<bool>(w + 2));
  vector<pair<int, int> > start;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == '.') {
        mp[i + 1][j + 1] = true;
        start.push_back(make_pair(i + 1, j + 1));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < start.size(); i++) {
    int sY = start[i].first;
    int sX = start[i].second;
    for (int j = i + 1; j < start.size(); j++) {
      int gY = start[j].first;
      int gX = start[j].second;
      queue<tuple<int, int, int, vector<vector<bool> > > > qu;
      vector<vector<bool> > cpMp = mpCopy(mp);
      cpMp[sY][sX] = false;
      qu.push(make_tuple(sY, sX, 0, cpMp));
      while (!qu.empty()) {
        tuple<int, int, int, vector<vector<bool> > > w = qu.front();
        qu.pop();
        int y = get<0>(w);
        int x = get<1>(w);
        int ws = get<2>(w);
        if (gY == y && gX == x) {
          ans = max(ans, ws);
          break;
        }
        vector<vector<bool> > currMp = get<3>(w);
        if (currMp[y - 1][x]) {
          vector<vector<bool> > cpMp = mpCopy(currMp);
          cpMp[y - 1][x] = false;
          qu.push(make_tuple(y - 1, x, ws + 1, currMp));
        }
        if (currMp[y][x + 1]) {
          vector<vector<bool> > cpMp = mpCopy(currMp);
          cpMp[y][x + 1] = false;
          qu.push(make_tuple(y, x + 1, ws + 1, currMp));
        }
        if (currMp[y + 1][x]) {
          vector<vector<bool> > cpMp = mpCopy(currMp);
          cpMp[y + 1][x] = false;
          qu.push(make_tuple(y + 1, x, ws + 1, currMp));
        }
        if (currMp[y][x - 1]) {
          vector<vector<bool> > cpMp = mpCopy(currMp);
          cpMp[y][x - 1] = false;
          qu.push(make_tuple(y, x - 1, ws + 1, currMp));
        }
      }
    }
  }
  cout << ans << "\n";
}
int main() { solver(); }
