#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int INF = 100000000;
ll a, b, c, i, j, l, m, n, ans, tmp, hoge, fuga, piyo;
int h, w;
int MAP[20][20];
int d[20][20];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int get_longest(int i, int j, int h, int w) {
  int max = 0;
  queue<ii> que;
  for (int hh = 0; hh < h; hh++) {
    for (int ww = 0; ww < w; ww++) {
      d[hh][ww] = INF;
    }
  }
  d[i][j] = 0;
  que.push(ii(i, j));
  while (que.size()) {
    ii p = que.front();
    que.pop();
    for (int n = 0; n < 4; n++) {
      int nx = p.first + dx[n];
      int ny = p.second + dy[n];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && MAP[nx][ny] == 1 &&
          d[nx][ny] == INF) {
        que.push(ii(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
        max = d[nx][ny] > max ? d[nx][ny] : max;
      }
    }
  }
  return max;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h + 1; i++) {
    string str;
    getline(cin, str);
    if (i == 0) continue;
    for (int j = 0; j < w; j++) {
      MAP[i - 1][j] = str[j] == '.' ? 1 : 0;
    }
  }
  int longest = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int l = get_longest(i, j, h, w);
      if (l > longest) {
        longest = l;
      }
    }
  }
  printf("%d", longest);
  return 0;
}
