#include <bits/stdc++.h>
using namespace std;
char s[30][30];
int dist[30][30];
bool visited[30][30];
int dx[] = {0, -1, 0, 1};
int dy[] = {1, 0, -1, 0};
int h, w;
int BFS(int x, int y, int z, int w) {
  queue<pair<int, int>> Q;
  Q.push({x, y});
  visited[x][y] = true;
  while (!Q.empty()) {
    pair<int, int> p = Q.front();
    Q.pop();
    for (int k = 0; k < 4; k++) {
      pair<int, int> q = p;
      q.first += dx[k];
      q.second += dy[k];
      if (q.first < 0 || q.first >= h || q.second < 0 || q.second >= w) {
        continue;
      }
      if (visited[q.first][q.second] || s[q.first][q.second] == '#') {
        continue;
      }
      dist[q.first][q.second] = dist[p.first][p.second] + 1;
      Q.push(q);
      visited[q.first][q.second] = true;
    }
  }
  return dist[z][w];
}
int main() {
  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 i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        continue;
      }
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (s[k][l] == '#') {
            continue;
          }
          for (int x = 0; x < 30; x++) {
            for (int y = 0; y < 30; y++) {
              dist[x][y] = 0;
              visited[x][y] = false;
            }
          }
          ans = max(BFS(i, j, k, l), ans);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
