#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[20][20];
  int c[20][20], d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  pair<int, int> g, p;
  queue<pair<int, int>> que;
  int h, w, o = 0;
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> s[i][j];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        memset(c, -1, sizeof(char) * 400);
        c[i][j] = 0;
        que.push({i, j});
        while (que.size()) {
          p = que.front();
          que.pop();
          for (int m = 0; m < 4; m++) {
            if (0 <= p.first + d[m][0] && p.first + d[m][0] < h &&
                0 <= p.second + d[m][1] && p.second + d[m][1] < w) {
              if (s[p.first + d[m][0]][p.second + d[m][1]] == '.' &&
                  c[p.first + d[m][0]][p.second + d[m][1]] == -1) {
                c[p.first + d[m][0]][p.second + d[m][1]] =
                    c[p.first][p.second] + 1;
                que.push({p.first + d[m][0], p.second + d[m][1]});
              }
            }
          }
        }
        for (int k = 0; k < h; k++)
          for (int l = 0; l < w; l++)
            if (s[k][l] == '.') o = max(o, c[k][l]);
      }
    }
  }
  cout << o << endl;
}
