#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int h, w;
  const int INF = 10e8;
  cin >> h >> w;
  bool d[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '.')
        d[i][j] = true;
      else
        d[i][j] = false;
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int map[h][w];
      queue<pair<int, int>> q;
      q.push(make_pair(i, j));
      for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) map[i][j] = INF;
      map[i][j] = 0;
      while (!q.empty()) {
        pair<int, int> p = q.front();
        int x = p.first;
        int y = p.second;
        q.pop();
        if (x > 0) {
          if (d[x - 1][y]) {
            if (map[x][y] + 1 < map[x - 1][y]) {
              map[x - 1][y] = map[x][y] + 1;
              q.push(make_pair(x - 1, y));
            }
          }
        }
        if (y > 0) {
          if (d[x][y - 1]) {
            if (map[x][y] + 1 < map[x][y - 1]) {
              map[x][y - 1] = map[x][y] + 1;
              q.push(make_pair(x, y - 1));
            }
          }
        }
        if (x < h - 1) {
          if (d[x + 1][y]) {
            if (map[x][y] + 1 < map[x + 1][y]) {
              map[x + 1][y] = map[x][y] + 1;
              q.push(make_pair(x + 1, y));
            }
          }
        }
        if (y < w - 1) {
          if (d[x][y + 1]) {
            if (map[x][y] + 1 < map[x][y + 1]) {
              map[x][y + 1] = map[x][y] + 1;
              q.push(make_pair(x, y + 1));
            }
          }
        }
      }
      int max = 0;
      for (int x = 0; x < h; x++) {
        for (int y = 0; y < w; y++) {
          if (map[x][y] > max && map[x][y] != INF) max = map[x][y];
        }
      }
      if (max > ans) ans = max;
    }
  }
  cout << ans << endl;
  return 0;
}
