#include <bits/stdc++.h>
using namespace std;
int H, W;
char S[20][20];
int visited[20][20];
void bfs(int startH, int startW) {
  visited[startH][startW] = 0;
  deque<pair<int, int> > dq;
  dq.push_back(make_pair(startH, startW));
  while (dq.size() != 0) {
    pair<int, int> p = dq.front();
    dq.pop_front();
    int curH = p.first;
    int curW = p.second;
    if (curH > 0) {
      if (S[curH - 1][curW] == '.' && visited[curH - 1][curW] == -1) {
        dq.push_back(make_pair(curH - 1, curW));
        visited[curH - 1][curW] = visited[curH][curW] + 1;
      }
    }
    if (curH < H - 1) {
      if (S[curH + 1][curW] == '.' && visited[curH + 1][curW] == -1) {
        dq.push_back(make_pair(curH + 1, curW));
        visited[curH + 1][curW] = visited[curH][curW] + 1;
      }
    }
    if (curW > 0) {
      if (S[curH][curW - 1] == '.' && visited[curH][curW - 1] == -1) {
        dq.push_back(make_pair(curH, curW - 1));
        visited[curH][curW - 1] = visited[curH][curW] + 1;
      }
    }
    if (curW < W - 1) {
      if (S[curH][curW + 1] == '.' && visited[curH][curW + 1] == -1) {
        dq.push_back(make_pair(curH, curW + 1));
        visited[curH][curW + 1] = visited[curH][curW] + 1;
      }
    }
  }
}
int main(int argc, char **argv) {
  cin >> H >> W;
  for (int i = 0; i < (H); ++i)
    for (int j = 0; j < (W); ++j) cin >> S[i][j];
  int ans = 0;
  for (int is = 0; is < (H); ++is) {
    for (int js = 0; js < (W); ++js) {
      for (int i = 0; i < (H); ++i)
        for (int j = 0; j < (W); ++j) visited[i][j] = -1;
      bfs(is, js);
      for (int ig = 0; ig < (H); ++ig)
        for (int jg = 0; jg < (W); ++jg)
          if (visited[ig][jg] != -1) ans = max(ans, visited[ig][jg]);
    }
  }
  cout << ans << endl;
  return 0;
}
