#include <bits/stdc++.h>
using namespace std;
const int inf = 10e5;
char maze[100][100];
int n, m;
pair<int, int> s, g;
int d[100][100];
pair<int, int> v[4] = {pair<int, int>(1, 0), pair<int, int>(0, 1),
                       pair<int, int>(-1, 0), pair<int, int>(0, -1)};
int bfs() {
  queue<pair<int, int> > que;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) d[i][j] = inf;
  }
  que.push(s);
  d[s.first][s.second] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    if (p.first == g.first && p.second == g.second) break;
    for (int i = 0; i < 4; i++) {
      int nx = p.first + v[i].first;
      int ny = p.second + v[i].second;
      if (0 <= nx && nx < n && 0 <= ny && ny < m && maze[nx][ny] != '#' &&
          d[nx][ny] == inf) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[g.first][g.second];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> maze[i];
  int max = 0;
  for (int x1 = 0; x1 < n; x1++) {
    for (int y1 = 0; y1 < m; y1++) {
      for (int x2 = 0; x2 < n; x2++) {
        for (int y2 = 0; y2 < m; y2++) {
          s = pair<int, int>(x1, y1);
          g = pair<int, int>(x2, y2);
          int b = bfs();
          if (max < b && b != inf) max = b;
        }
      }
    }
  }
  cout << max << endl;
  return 0;
}
