#include <bits/stdc++.h>
using namespace std;
int h, w;
int s[21][21];
void dfs(int i, int j) {
  if (i - 1 < 0)
    ;
  else if (s[i - 1][j] == -1)
    ;
  else {
    s[i - 1][j] = s[i][j] + 1;
    dfs(i - 1, j);
  }
  if (i + 1 >= h)
    ;
  else if (s[i + 1][j] == -1)
    ;
  else {
    s[i + 1][j] = s[i][j] + 1;
    dfs(i + 1, j);
  }
  if (j - 1 < 0)
    ;
  else if (s[i][j - 1] == -1)
    ;
  else {
    s[i][j - 1] = s[i][j] + 1;
    dfs(i, j - 1);
  }
  if (j + 1 >= w)
    ;
  else if (s[i][j + 1] == -1)
    ;
  else {
    s[i][j + 1] = s[i][j] + 1;
    dfs(i, j + 1);
  }
  return;
}
int findmax() {
  int ans = 0;
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) {
      ans = max(ans, s[i][j]);
    }
  return ans;
}
int main() {
  cin >> h >> w;
  int sss[21][21];
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) {
      char ss;
      cin >> ss;
      if (ss == '.')
        sss[i][j] = 0;
      else if (ss == '#')
        sss[i][j] = -1;
    }
  int ans = 0;
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) {
      for (int ii = 0; ii < (h); ii++)
        for (int jj = 0; jj < (w); jj++) {
          s[ii][jj] = sss[ii][jj];
        }
      dfs(i, j);
      if (s[i][j] == '.') {
        ans = max(ans, findmax());
      }
    }
  cout << ans << endl;
  return 0;
}
