#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
int H, W;
char S[30][30];
int dfs(P st) {
  vector<vector<int>> dis(H + 1, vector<int>(W + 1, 1000000));
  dis[st.first][st.second] = 0;
  int max_dis = 0;
  queue<P> q;
  q.push(st);
  while (!q.empty()) {
    int i, j;
    i = q.front().first;
    j = q.front().second;
    q.pop();
    if (i - 1 >= 1 && S[i - 1][j] == '.' && dis[i - 1][j] == 1000000) {
      dis[i - 1][j] = dis[i][j] + 1;
      max_dis = dis[i][j] + 1;
      q.push(P(i - 1, j));
    }
    if (i + 1 <= H && S[i + 1][j] == '.' && dis[i + 1][j] == 1000000) {
      dis[i + 1][j] = dis[i][j] + 1;
      max_dis = dis[i][j] + 1;
      q.push(P(i + 1, j));
    }
    if (j - 1 >= 1 && S[i][j - 1] == '.' && dis[i][j - 1] == 1000000) {
      dis[i][j - 1] = dis[i][j] + 1;
      max_dis = dis[i][j] + 1;
      q.push(P(i, j - 1));
    }
    if (j + 1 <= W && S[i][j + 1] == '.' && dis[i][j + 1] == 1000000) {
      dis[i][j + 1] = dis[i][j] + 1;
      max_dis = dis[i][j] + 1;
      q.push(P(i, j + 1));
    }
  }
  return (max_dis);
}
int main() {
  cin >> H >> W;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) cin >> S[i][j];
  }
  int max = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j < W; j++) {
      if (S[i][j] == '.') {
        int tmp = dfs(P(i, j));
        if (tmp > max) max = tmp;
      }
    }
  }
  cout << max << endl;
}
