#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
char maze[21][21];
int dist[21][21];
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
void reset_dist() {
  for (int i = 0; i < (21); ++i)
    for (int j = 0; j < (21); ++j) dist[i][j] = 0;
}
int main() {
  int h, w;
  cin >> h >> w;
  int ans = 0;
  for (int i = 0; i < (21); ++i)
    for (int j = 0; j < (21); ++j) maze[i][j] = '#';
  for (int i = 0; i < (h); ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < (s.size()); ++j) {
      dist[i][j] = 0;
      maze[i + 1][j + 1] = s[j];
    }
  }
  for (int i = 1; i < 21; ++i) {
    for (int j = 1; j < 21; ++j) {
      int sx, sy;
      sy = i;
      sx = j;
      reset_dist();
      if (maze[sy][sx] == '#') continue;
      queue<P> Q;
      P p(0, 0);
      p.first = sy;
      p.second = sx;
      Q.push(p);
      int current_max = 0;
      while (1) {
        P p(0, 0);
        p = Q.front();
        Q.pop();
        int x, y;
        x = p.second;
        y = p.first;
        for (int i = 0; i < (4); ++i) {
          if (((y + dy[i]) > 20) || ((x + dx[i]) > 20)) continue;
          if (dist[y + dy[i]][x + dx[i]] == 0) {
            if (maze[y + dy[i]][x + dx[i]] == '#') continue;
            dist[y + dy[i]][x + dx[i]] = dist[y][x] + 1;
            current_max = max(current_max, dist[y + dy[i]][x + dx[i]]);
            P p(0, 0);
            p.first = y + dy[i];
            p.second = x + dx[i];
            Q.push(p);
          }
        }
        if (Q.empty()) break;
      }
      ans = max(ans, current_max);
    }
  }
  cout << ans << endl;
}
