#include <bits/stdc++.h>
using namespace std;
const int MAXH = 20;
bool isWall[MAXH][MAXH];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
bool visited[MAXH][MAXH];
int solve(int r, int c, int h, int w) {
  for (int i = 0; i < MAXH; i++) fill(visited[i], visited[i] + MAXH, false);
  queue<tuple<int, int, int>> q;
  q.push(make_tuple(r, c, 0));
  visited[r][c] = true;
  int ans = 0;
  while (!q.empty()) {
    tuple<int, int, int> t = q.front();
    q.pop();
    r = get<0>(t);
    c = get<1>(t);
    int d = get<2>(t);
    ans = d;
    for (int i = 0; i < 4; i++) {
      int newr = r + dx[i];
      int newc = c + dy[i];
      if (!isWall[newr][newc] && !visited[newr][newc] && newr >= 0 &&
          newr < h && newc >= 0 && newc < w) {
        visited[newr][newc] = true;
        q.push(make_tuple(newr, newc, d + 1));
      }
    }
  }
  return ans;
}
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) isWall[i][j] = s[j] == '#';
  }
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) ans = max(ans, solve(i, j, h, w));
  cout << ans << endl;
  return 0;
}
