#include <bits/stdc++.h>
using namespace std;
int yoko[4] = {-1, 0, 0, 1};
int tate[4] = {0, -1, 1, 0};
int bfs(const vector<vector<char>> &maze, vector<vector<int>> &arrived, int h,
        int w) {
  queue<pair<int, int>> que;
  pair<int, int> first = make_pair(h, w);
  que.push(first);
  int ret = 0;
  arrived[h][w] = 0;
  while (!que.empty()) {
    pair<int, int> v = que.front();
    que.pop();
    for (int dir = 0; dir < 4; dir++) {
      int next_h = v.first + tate[dir];
      int next_w = v.second + yoko[dir];
      if (maze[next_h][next_w] == '#') continue;
      if (arrived[next_h][next_w] != -1) continue;
      arrived[next_h][next_w] = arrived[v.first][v.second] + 1;
      ret = max(ret, arrived[next_h][next_w]);
      pair<int, int> next = make_pair(next_h, next_w);
      que.push(next);
    }
  }
  return ret;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> maze(h + 2, vector<char>(w + 2, '#'));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> maze[i][j];
    }
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = i; j <= w; j++) {
      vector<vector<int>> arrived(h + 1, vector<int>(w + 1, -1));
      ans = max(ans, bfs(maze, arrived, i, j));
    }
  }
  cout << ans << endl;
}
