#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
  int i, w;
  void fil(int a, int b, int c, int d) { x = a, y = b, i = c, w = d; }
};
int main() {
  int n, m, max = -1, move[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  char mp[25][25];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", mp[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++)
      if (mp[i][j] == '.') {
        for (int l = 0; l < n; l++)
          for (int k = 0; k < m; k++)
            if (mp[l][k] == '.' && !(i == l && j == k)) {
              point x;
              x.fil(i, j, 0, 0);
              queue<point> q;
              q.push(x);
              while (!q.empty()) {
                x = q.front();
                q.pop();
                for (int s = 0; s < 4; s++) {
                  int xx = x.x + move[s][0];
                  int yy = x.y + move[s][1];
                  if (xx < 0 || xx >= n || yy < 0 || yy >= m ||
                      mp[xx][yy] == '#')
                    continue;
                  point y;
                  y.fil(xx, yy, x.i + 1, 0);
                  q.push(y);
                  if (y.x == l && y.y == k) {
                    if (y.i > max) max = y.i;
                    goto to;
                  }
                }
              }
            to:
              1;
            }
      }
  }
  printf("%d", max);
  return 0;
}
