#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y, step;
} old, news;
int main() {
  int x, y, max = 0, temp;
  char mp[25][25];
  bool np[25][25];
  queue<struct node> q;
  scanf("%d%d", &x, &y);
  for (int i = 0; i < x; i++) scanf("%s", mp[i]);
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      temp = 0;
      for (int m = 0; m < 25; m++)
        for (int n = 0; n < 25; n++) np[m][n] = false;
      np[i][j] = true;
      old.x = i;
      old.y = j;
      old.step = 0;
      q.push(old);
      while (!q.empty()) {
        old = q.front();
        q.pop();
        for (int p = 0; p < 4; p++) {
          news = old;
          if (p == 0 && news.x > 0 && mp[news.x - 1][news.y] != '#' &&
              np[news.x - 1][news.y] != true) {
            news.x--;
            news.step++;
            np[news.x][news.y] = true;
            q.push(news);
            if (news.step > max) max = news.step;
          }
          if (p == 1 && news.x < x - 1 && mp[news.x + 1][news.y] != '#' &&
              np[news.x + 1][news.y] != true) {
            news.x++;
            news.step++;
            np[news.x][news.y] = true;
            q.push(news);
            if (news.step > max) max = news.step;
          }
          if (p == 2 && news.y > 0 && mp[news.x][news.y - 1] != '#' &&
              np[news.x][news.y - 1] != true) {
            news.y--;
            news.step++;
            np[news.x][news.y] = true;
            q.push(news);
            if (news.step > max) max = news.step;
          }
          if (p == 3 && news.y < y - 1 && mp[news.x][news.y + 1] != '#' &&
              np[news.x][news.y + 1] != true) {
            news.y++;
            news.step++;
            np[news.x][news.y] = true;
            q.push(news);
            if (news.step > max) max = news.step;
          }
        }
      }
      if (temp > max) max = temp;
    }
  }
  printf("%d\n", max);
}
