#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " , ";
  __f(comma + 1, args...);
}
const int SQRTN = 1003;
const int LOGN = 22;
const long double PI = acos(-1);
const int INF = 1000000000;
const int MOD = 1000000007;
const int FMOD = 998244353;
const long double eps = 1e-9;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
T gcd(T a, T b) {
  return (b ? __gcd(a, b) : a);
}
template <typename T>
T lcm(T a, T b) {
  return (a * (b / gcd(a, b)));
}
int add(int a, int b, int c) {
  int res = a + b;
  return (res >= c ? res - c : res);
}
int mod_neg(int a, int b, int c) {
  int res;
  if (abs(a - b) < c)
    res = a - b;
  else
    res = (a - b) % c;
  return (res < 0 ? res + c : res);
}
int mul(int a, int b, int c) {
  long long res = (long long)a * b;
  return (res >= c ? res % c : res);
}
long long mulmod(long long a, long long b, long long m) {
  long long q = (long long)(((long LD)a * (long LD)b) / (long LD)m);
  long long r = a * b - q * m;
  if (r > m) r %= m;
  if (r < 0) r += m;
  return r;
}
template <typename T>
T expo(T e, T n) {
  T x = 1, p = e;
  while (n) {
    if (n & 1) x = x * p;
    p = p * p;
    n >>= 1;
  }
  return x;
}
template <typename T>
T power(T e, T n, T m) {
  T x = 1, p = e;
  while (n) {
    if (n & 1) x = mul(x, p, m);
    p = mul(p, p, m);
    n >>= 1;
  }
  return x;
}
template <typename T>
T extended_euclid(T a, T b, T& x, T& y) {
  T xx = 0, yy = 1;
  y = 0;
  x = 1;
  while (b) {
    T q = a / b, t = b;
    b = a % b;
    a = t;
    t = xx;
    xx = x - q * xx;
    x = t;
    t = yy;
    yy = y - q * yy;
    y = t;
  }
  return a;
}
template <typename T>
T mod_inverse(T a, T n) {
  T x, y, z = 0;
  T d = extended_euclid(a, n, x, y);
  return (d > 1 ? -1 : mod_neg(x, z, n));
}
void solve();
signed main() {
  cout << fixed << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int testcase = 1; testcase < t + 1; testcase++) {
    solve();
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
string mat[20];
int dp[20][20][20][20];
void solve() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> mat[i];
  }
  memset(dp, 63, sizeof dp);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (mat[i][j] == '.') {
        if (i > 0 and mat[i - 1][j] == '.') {
          dp[i][j][i - 1][j] = 1;
          dp[i - 1][j][i][j] = 1;
        }
        if (j > 0 and mat[i][j - 1] == '.') {
          dp[i][j][i][j - 1] = 1;
          dp[i][j - 1][i][j] = 1;
        }
      }
    }
  }
  for (int k1 = 0; k1 < 20; k1++) {
    for (int k2 = 0; k2 < 20; k2++) {
      for (int i1 = 0; i1 < 20; i1++) {
        for (int i2 = 0; i2 < 20; i2++) {
          for (int j1 = 0; j1 < 20; j1++) {
            for (int j2 = 0; j2 < 20; j2++) {
              dp[i1][i2][j1][j2] = min(dp[i1][i2][j1][j2],
                                       dp[i1][i2][k1][k2] + dp[k1][k2][j1][j2]);
            }
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 20; j++) {
      for (int k = 0; k < 20; k++) {
        for (int l = 0; l < 20; l++) {
          if (dp[i][j][k][l] < 160000) {
            ans = max(ans, dp[i][j][k][l]);
          }
        }
      }
    }
  }
  cout << ans;
}
