#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to;
  int cost;
};
using P = pair<int, int>;
int V;
vector<edge> G[400];
int d[400];
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d + V, 1e+9);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}
int main() {
  int H, W;
  cin >> H >> W;
  V = H * W;
  int s[H][W];
  int ans = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      string t;
      cin >> t;
      if (t[0] == '#')
        s[i][j] = 0;
      else
        s[i][j] = 1;
    }
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W - 1; ++j) {
      if (s[i][j] == 1 && s[i][j + 1] == 1) {
        edge e;
        e = {i + j * H, 1};
        G[i + (j + 1) * H].push_back(e);
        e = {i + (j + 1) * H, 1};
        G[i + j * H].push_back(e);
      }
    }
  }
  for (int i = 0; i < H - 1; ++i) {
    for (int j = 0; j < W; ++j) {
      if (s[i][j] == 1 && s[i + 1][j] == 1) {
        edge e;
        e = {i + j * H, 1};
        G[(i + 1) + j * H].push_back(e);
        e = {(i + 1) + j * H, 1};
        G[i + j * H].push_back(e);
      }
    }
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (s[i][j] == 0) continue;
      dijkstra(i + j * H);
      for (int k = 0; k < H; ++k) {
        for (int l = 0; l < W; ++l) {
          if (i + j * H >= k + l * H) continue;
          if (s[k][l] == 0) continue;
          if (d[k + l * H] != 1e+9) ans = max(ans, d[k + l * H]);
        }
      }
    }
  }
  cout << ans << endl;
}
