#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int h, w;
vector<string> s;
vector<vector<bool>> visit;
int main() {
  cin >> h >> w;
  s.resize(h);
  visit.resize(h);
  for (int i = 0; i <= h - 1; ++i) visit[i].resize(w);
  for (int i = 0; i <= h - 1; ++i) cin >> s[i];
  int max_d = 0, ans = 0;
  for (int sh = 0; sh <= h - 1; ++sh)
    for (int sw = 0; sw <= w - 1; ++sw) {
      for (int i = 0; i <= h - 1; ++i)
        for (int j = 0; j <= w - 1; ++j) {
          if (s[i][j] == '#')
            visit[i][j] = true;
          else
            visit[i][j] = false;
        }
      queue<pair<int, int>> q;
      int dist[h][w];
      for (int i = 0; i <= h - 1; ++i)
        for (int j = 0; j <= w - 1; ++j) {
          dist[i][j] = 0;
        }
      dist[sh][sw] = 0;
      q.push(pair<int, int>(sh, sw));
      int depth = 0;
      while (!q.empty()) {
        pair<int, int> qq = q.front();
        q.pop();
        int hh = qq.first, ww = qq.second;
        visit[hh][ww] = true;
        if (hh != h - 1 && !visit[hh + 1][ww]) {
          q.push(pair<int, int>(hh + 1, ww));
          visit[hh + 1][ww] = true;
          dist[hh + 1][ww] = dist[hh][ww] + 1;
        }
        if (ww != w - 1 && !visit[hh][ww + 1]) {
          q.push(pair<int, int>(hh, ww + 1));
          visit[hh][ww + 1] = true;
          dist[hh][ww + 1] = dist[hh][ww] + 1;
        }
        if (hh != 0 && !visit[hh - 1][ww]) {
          q.push(pair<int, int>(hh - 1, ww));
          visit[hh - 1][ww] = true;
          dist[hh - 1][ww] = dist[hh][ww] + 1;
        }
        if (ww != 0 && !visit[hh][ww - 1]) {
          q.push(pair<int, int>(hh, ww - 1));
          visit[hh][ww - 1] = true;
          dist[hh][ww - 1] = dist[hh][ww] + 1;
        }
        depth++;
      }
      max_d = 0;
      for (int i = 0; i <= h - 1; ++i)
        for (int j = 0; j <= w - 1; ++j) {
          max_d = max(max_d, dist[i][j]);
        }
      ans = max(ans, max_d);
    }
  cout << ans << endl;
  return 0;
}
