#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
bool seen[30][30];
string vec[25];
int ans[30][30];
int h, w;
void dfs(int a, int b) {
  seen[a][b] = true;
  for (int dir = 0; dir < 4; dir++) {
    int nh = a + dx[dir];
    int nw = b + dy[dir];
    if (nh < 0 || nh >= h || nw < 0 || nw >= w) continue;
    if (vec[nh][nw] == '#') continue;
    if (seen[nh][nw] == true) continue;
    ans[nh][nw] = ans[a][b] + 1;
    dfs(nh, nw);
  }
}
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, (a % b));
  }
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long mpower(long long a, long long b, long long c) {
  int z;
  if (b == 0) {
    z = 1;
    z %= c;
    return z;
  }
  if (b == 1) {
    z = a;
    z %= c;
    return z;
  } else {
    return (((mpower(a, b / 2, c)) * (mpower(a, b / 2, c)) % c) *
            mpower(a, b % 2, c) % c);
  }
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> vec[i];
  }
  int a, b;
  int answer = 0, p = 0;
  for (int i = 0; i < h * w; i++) {
    a = i / w, b = i % w;
    if (vec[a][b] == '.') {
      memset(seen, 0, sizeof(seen));
      memset(ans, 0, sizeof(ans));
      dfs(a, b);
      for (int j = 0; j < h; j++) {
        for (int k = 0; k < w; k++) {
          answer = max(answer, ans[j][k]);
        }
      }
    }
  }
  cout << answer << endl;
}
