#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
const long long int mod = 1e9 + 7;
const long long int maxn = 100001;
long long int power(long long int x, long long int n) {
  long long int res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}
string s[400];
long long int h, w;
bool isvalid(long long int i, long long int j) {
  return (i < h && i >= 0 && j < w && j >= 0 && s[i][j] == '.');
}
vector<long long int> g[4000];
vector<long long int> djikstra(long long int src) {
  bool vis[400];
  memset(vis, 0, sizeof(vis));
  vector<long long int> dist(h * w + 10, 1e18);
  queue<long long int> q;
  dist[src] = 0;
  q.push(src);
  while (!q.empty()) {
    long long int u = q.front();
    q.pop();
    for (auto v : g[u]) {
      if (!vis[v]) {
        vis[v] = 1;
        dist[v] = dist[u] + 1;
        q.push(v);
      }
    }
  }
  return dist;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> h >> w;
  for (long long int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) {
      for (long long int ii = i - 1; ii <= i + 1; ii++) {
        for (long long int jj = j - 1; jj <= j + 1; jj++) {
          if (abs(i - ii) + abs(j - jj) == 1) {
            if (isvalid(i, j) && isvalid(ii, jj)) {
              g[i * w + j].push_back(ii * w + jj);
            }
          }
        }
      }
    }
  }
  long long int ans = 1;
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) {
      if (isvalid(i, j)) {
        vector<long long int> d = djikstra(i * w + j);
        for (auto x : d) {
          if (!(x > 1e15)) {
            ans = max(ans, x);
          }
        }
      }
    }
  }
  cout << ans << endl;
}
