#include <bits/stdc++.h>
using namespace std;
long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v,
    w, x, y, z;
int xy[][2] = {{1, 0}, {0, 1},   {-1, 0}, {0, -1},
               {1, 1}, {-1, -1}, {1, -1}, {-1, 1}};
int bfs(vector<string> maze, pair<int, int> p) {
  int maxfar = 0;
  vector<vector<int> > dist(h, vector<int>(w, -1));
  dist[p.second][p.first] = 0;
  queue<pair<int, int> > q;
  q.push(p);
  while (!q.empty()) {
    pair<int, int> pp = q.front();
    q.pop();
    x = pp.first;
    y = pp.second;
    for (int i = 0; i < 4; ++i) {
      int xx = xy[i][0] + x;
      int yy = xy[i][1] + y;
      if (xx < w && yy < h && xx >= 0 && yy >= 0 && maze[yy][xx] != '#' &&
          dist[yy][xx] < 0) {
        dist[yy][xx] = dist[y][x] + 1;
        q.push(make_pair(xx, yy));
      }
    }
  }
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      if (dist[i][j] > maxfar) maxfar = dist[i][j];
  return maxfar;
}
int main(void) {
  vector<string> maze;
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    string ss;
    cin >> ss;
    maze.emplace_back(ss);
  }
  int maxdist = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (maze[j][i] == '#') continue;
      b = bfs(maze, make_pair(j, i));
      if (b > maxdist) maxdist = b;
    }
  }
  cout << maxdist << endl;
  return 0;
}
