#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chmax(T &a, const T &b) {
  if (a < b) a = b;
}
template <class T>
inline void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
const long long INF = 1LL << 60;
const long long MOD = (long long)1e9 + 7;
const long long MAX = (long long)1e5 + 10;
class Node {
 public:
  vector<long> to;
  long long dis = 0;
  bool seen = false;
  bool finish = false;
  Node() { ; };
};
vector<Node *> vGr;
queue<int> vq;
queue<int> vq2;
void bfs(int vertex) {
  auto thisv = vGr[vertex];
  thisv->seen = true;
  for (auto el : thisv->to) {
    if (!vGr[el]->seen) vq2.push(el);
  }
  return;
}
long long H, W;
long long ind(long long h, long long w) { return h * W + w; }
int main(void) {
  cin >> H >> W;
  vector<int> S;
  for (int i = 0; i < (int)(H); i++) {
    string s;
    cin >> s;
    for (int j = 0; j < (int)(W); j++) {
      if (s[j] == '#')
        S.push_back(0);
      else
        S.push_back(1);
    }
  }
  vGr.resize(H * W);
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++) vGr[ind(i, j)] = new Node();
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++) {
      if (!S[ind(i, j)]) continue;
      if (i > 0 && S[ind(i - 1, j)])
        vGr[ind(i, j)]->to.push_back(ind(i - 1, j));
      if (i < H - 1 && S[ind(i + 1, j)])
        vGr[ind(i, j)]->to.push_back(ind(i + 1, j));
      if (j > 0 && S[ind(i, j - 1)])
        vGr[ind(i, j)]->to.push_back(ind(i, j - 1));
      if (j < W - 1 && S[ind(i, j + 1)])
        vGr[ind(i, j)]->to.push_back(ind(i, j + 1));
    }
  long long ans = 0;
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++) {
      if (!S[ind(i, j)]) continue;
      if (vGr[ind(i, j)]->to.size() > 2) continue;
      for (auto el : vGr) el->seen = false;
      long long ans_this = 0;
      vq.push(ind(i, j));
      while (vq.size()) {
        while (vq.size()) {
          long long ne = vq.front();
          bfs(ne);
          vq.pop();
        }
        swap(vq, vq2);
        if (vq.size()) ans_this++;
      }
      chmax(ans, ans_this);
    }
  cout << ans << endl;
  return 0;
}
