#include <bits/stdc++.h>
using namespace std;
int maze[25][25];
int mark[25][25];
int wayx[] = {0, 0, 1, -1};
int wayy[] = {1, -1, 0, 0};
inline long long read() {
  char c = getchar();
  long long flag = 1, ans = 0;
  ;
  while (c < '0' || c > '9') {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ans = ans * 10 + c - '0';
    c = getchar();
  }
  return (ans * flag);
}
struct node {
  int i, j;
  node(int a, int b) {
    i = a;
    j = b;
  }
};
int bfs(int x, int y, int ex, int ey, int h, int w) {
  memset(mark, 0, sizeof(mark));
  queue<node> qe;
  qe.push(node(x, y));
  mark[x][y] = 1;
  int i = 0, j = 0;
  while (!qe.empty()) {
    i = qe.front().i, j = qe.front().j;
    qe.pop();
    for (int n = 0; n < 4; ++n) {
      if (i + wayx[n] >= 0 && i + wayx[n] < h && j + wayy[n] >= 0 &&
          j + wayy[n] < w) {
        if (!mark[i + wayx[n]][j + wayy[n]] && maze[i + wayx[n]][j + wayy[n]]) {
          mark[i + wayx[n]][j + wayy[n]] = mark[i][j] + 1;
          qe.push(node(i + wayx[n], j + wayy[n]));
        }
      }
    }
  }
  return mark[ex][ey] - 1;
}
int main() {
  int h = read(), w = read();
  memset(maze, 0, sizeof(maze));
  getchar();
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char s;
      scanf("%c", &s);
      if (s == '.') maze[i][j] = 1;
    }
    getchar();
  }
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      for (int k = 0; k < h; ++k) {
        for (int l = 0; l < w; ++l) {
          if (maze[i][j] && maze[k][l]) {
            ans = max(bfs(i, j, k, l, h, w), ans);
          }
        }
      }
    }
  }
  cout << ans << endl;
}
