#include <bits/stdc++.h>
template <class T>
inline void read(T &x) {
  x = 0;
  char ch = getchar(), w = 0;
  while (!isdigit(ch)) w = ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = w ? -x : x;
  return;
}
const long long int M = 1e9 + 7;
const long long int MAX = 1e5 + 7;
using namespace std;
bool comp(long long int a, long long int b) { return a > b; }
void printQ(vector<long long int> q) {
  cout << "v->  ";
  for (long long int i = 0; i < q.size(); i++) {
    cout << q[i] << " ";
  }
  cout << endl;
}
long long int solve(long long int sx, long long int sy, long long int ex,
                    long long int ey, vector<vector<long long int>> &vis,
                    long long int n, long long int m, string s[]) {
  if (sx == ex && sy == ey) {
    return 0;
  }
  vector<long long int> dx({0, -1, 0, 1});
  vector<long long int> dy({-1, 0, 1, 0});
  vis[sx][sy] = 1;
  long long int ans = INT_MAX;
  for (long long int i = 0; i < 4; i++) {
    long long int nx = sx + dx[i];
    long long int ny = sy + dy[i];
    if (nx >= 0 && nx < n && ny >= 0 && ny < m && vis[nx][ny] == 0 &&
        s[nx][ny] == '.') {
      long long int dis = solve(nx, ny, ex, ey, vis, n, m, s);
      if (dis != INT_MAX) {
        ans = min(ans, 1 + dis);
      }
    }
  }
  vis[sx][sy] = 0;
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  string s[n];
  for (long long int i = 0; i < n; i++) cin >> s[i];
  long long int ans = 0;
  vector<vector<long long int>> vis(n, vector<long long int>(m, 0));
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      for (long long int ii = 0; ii < n; ii++) {
        for (long long int jj = 0; jj < m; jj++) {
          if (s[i][j] == '.' && s[ii][jj] == '.' && i != ii && j != jj) {
            ans = max(ans, solve(i, j, ii, jj, vis, n, m, s));
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
