#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, max = 0;
  cin >> h >> w;
  vector<string> maze(h);
  vector<int> nx = {1, 0, -1, 0};
  vector<int> ny = {0, 1, 0, -1};
  for (int i = 0; i < h; i++) cin >> maze[i];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      vector<vector<int>> dist(h, vector<int>(w, -1));
      queue<pair<int, int>> que;
      dist[i][j] = 0;
      que.push(pair<int, int>(i, j));
      while (!que.empty()) {
        pair<int, int> v = que.front();
        que.pop();
        for (int k = 0; k < 4; k++) {
          if (v.first == 0 && k == 2) continue;
          if (v.first == h - 1 && k == 0) continue;
          if (v.second == 0 && k == 3) continue;
          if (v.second == w - 1 && k == 1) continue;
          if (dist[v.first + nx[k]][v.second + ny[k]] != -1 ||
              maze[v.first + nx[k]][v.second + ny[k]] == '#')
            continue;
          dist[v.first + nx[k]][v.second + ny[k]] = dist[v.first][v.second] + 1;
          if (max < dist[v.first + nx[k]][v.second + ny[k]])
            max = dist[v.first + nx[k]][v.second + ny[k]];
          que.push(pair<int, int>(v.first + nx[k], v.second + ny[k]));
        }
      }
    }
  }
  cout << max << endl;
}
