#include <bits/stdc++.h>
using namespace std;
int H, W;
char s[20][20];
int d[20][20][20][20];
bool used[20][20];
int dh[4] = {-1, 1, 0, 0};
int dw[4] = {0, 0, -1, 1};
bool isIn(int h, int w) { return (h >= 0 && h < H && w >= 0 && w < W); }
void clear() {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      used[i][j] = false;
    }
  }
}
int ans = 0;
void bfs(int sh, int sw, int d) {
  queue<pair<pair<int, int>, int> > que;
  que.push(pair<pair<int, int>, int>(pair<int, int>(sh, sw), 0));
  while (!que.empty()) {
    pair<pair<int, int>, int> top = que.front();
    que.pop();
    int h = top.first.first;
    int w = top.first.second;
    int d = top.second;
    used[h][w] = true;
    ans = max(ans, d);
    for (int i = 0; i < 4; i++) {
      if (isIn(h + dh[i], w + dw[i]) && !used[h + dh[i]][w + dw[i]] &&
          s[h + dh[i]][w + dw[i]] == '.') {
        que.push(pair<pair<int, int>, int>(pair<int, int>(h + dh[i], w + dw[i]),
                                           d + 1));
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(10) << fixed;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      clear();
      if (s[i][j] == '.') bfs(i, j, 0);
    }
  }
  cout << ans << endl;
}
