#include <bits/stdc++.h>
using namespace std;
struct pos {
  int tate;
  int yoko;
};
int main() {
  int t, y;
  cin >> t >> y;
  vector<string> masu(t);
  for (int i = 0; i <= t - 1; i++) {
    cin >> masu[i];
  }
  int kotae = 0;
  for (int i = 0; i <= t - 1; i++) {
    for (int j = 0; j <= y - 1; j++) {
      vector<vector<int>> dis(t, vector<int>(y));
      for (int k = 0; k <= t - 1; k++) {
        for (int l = 0; l <= y - 1; l++) {
          dis[k][l] = 0;
        }
      }
      queue<pos> que;
      que.push({i, j});
      vector<int> tatemove{0, 0, 1, -1};
      vector<int> yokomove{1, -1, 0, 0};
      pos now;
      int saidai = 0;
      while (1) {
        now = que.front();
        que.pop();
        for (int i = 0; i <= 3; i++) {
          pos next;
          next.tate = now.tate + tatemove[i];
          next.yoko = now.yoko + yokomove[i];
          if (next.tate >= 0 && next.tate <= t - 1 && next.yoko >= 0 &&
              next.yoko <= y - 1) {
            if (masu[next.tate][next.yoko] != '#' &&
                dis[next.tate][next.yoko] == 0) {
              dis[next.tate][next.yoko] = dis[now.tate][now.yoko] + 1;
              que.push(next);
              if (saidai <= dis[next.tate][next.yoko]) {
                saidai = dis[next.tate][next.yoko];
              }
            }
          }
        }
        if (que.empty()) {
          break;
        }
      }
      if (kotae <= saidai) {
        kotae = saidai;
      }
    }
  }
  cout << kotae << endl;
  return 0;
}
