#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  while (long long r = a % b) a = b, b = r;
  return b;
}
class mod {
 public:
  long long val;
  mod(long long v) { val = v % (long long)(1e9 + 7); }
  mod() { val = 0; }
  void operator-=(const mod &v) {
    val -= v.val;
    if (val < 0) val += (long long)(1e9 + 7);
  }
  void operator+=(const mod &v) {
    if (val + v.val >= (long long)(1e9 + 7)) val -= (long long)(1e9 + 7);
    val += v.val;
  }
  void operator+=(long long &v) {
    if (val + v >= (long long)(1e9 + 7)) val -= (long long)(1e9 + 7);
    val += v;
  }
  void operator*=(const mod &v) {
    val *= v.val;
    val %= (long long)(1e9 + 7);
  }
  void operator*=(long long &v) {
    val *= v;
    val %= (long long)(1e9 + 7);
  }
  long long modinv(long long a) {
    long long b = (long long)(1e9 + 7), u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    u %= (long long)(1e9 + 7);
    if (u < 0) u += (long long)(1e9 + 7);
    return u;
  }
  void operator/=(const mod &v) {
    val *= modinv(v.val);
    val %= (long long)(1e9 + 7);
  }
  void operator/=(long long &v) {
    val *= modinv(v);
    val %= (long long)(1e9 + 7);
  }
};
struct UnionFind {
  vector<int> par;
  vector<int> childN;
  long long r = 0;
  UnionFind(int N) : par(N), childN(N) {
    for (int i = 0; i < N; i++) par[i] = i, childN[i] = 1;
  }
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
    r -= childN[rx] * (childN[rx] - 1) / 2;
    r -= childN[ry] * (childN[ry] - 1) / 2;
    childN[ry] += childN[rx];
    childN[rx] = 0;
    r += childN[ry] * (childN[ry] - 1) / 2;
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
class WarshallFloyd {
 public:
  vector<vector<int>> d;
  int n;
  WarshallFloyd(int _n) : n(_n) {
    d.resize(n, vector<int>(n, (long long)(1e9 + 7)));
  }
  void run() {
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          if (d[i][k] < (long long)(1e9 + 7) && d[k][i] < (long long)(1e9 + 7))
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  }
};
using ipair = pair<int, pair<int, int>>;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; };
bool operator<(const ipair a, const ipair b) { return a.first < b.first; };
using xpair = pair<int, int>;
bool operator>(const xpair &a, const xpair &b) {
  return a.second > b.second || (a.second == b.second && a.first > b.first);
};
bool operator<(const xpair &a, const xpair &b) {
  return a.second < b.second || (a.second == b.second && a.first > b.first);
};
bool operator==(const xpair &a, const xpair &b) { return a.first == b.first; };
int main() {
  int h, w;
  cin >> h >> w;
  WarshallFloyd wf(h * w);
  vector<vector<bool>> s(h, vector<bool>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      s[i][j] = c == '.';
      if (j > 0 && s[i][j] && s[i][j - 1]) {
        int p = i * w + j;
        int q = p - 1;
        wf.d[q][p] = wf.d[p][q] = 1;
      }
      if (i > 0 && s[i][j] && s[i - 1][j]) {
        int p = (i - 1) * w + j;
        int q = i * w + j;
        wf.d[q][p] = wf.d[p][q] = 1;
      }
    }
  wf.run();
  int r = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (!s[i][j]) continue;
      for (int p = 0; p < h; p++)
        for (int q = 0; q < w; q++) {
          if (!s[p][q]) continue;
          int sc = wf.d[i * w + j][p * w + q];
          if (sc > r && sc < (long long)(1e9 + 7)) r = sc;
        }
    }
  printf("%d", r);
  return 0;
}
