#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
signed main() {
  int h, w;
  cin >> h >> w;
  string* maze = new string[h];
  for (int i = 0; i < (int)(h); i++) {
    cin >> maze[i];
  }
  int ans = 0;
  int dx[] = {1, 0, -1, 0};
  int dy[] = {0, 1, 0, -1};
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      for (int k = 0; k < (int)(h); k++) {
        for (int l = 0; l < (int)(w); l++) {
          if (maze[i][j] == '#' || maze[k][l] == '#') continue;
          bool** used = new bool*[h];
          for (int m = 0; m < (int)(h); m++) {
            used[m] = new bool[w];
            fill(used[m], used[m] + w, false);
          }
          used[i][j] = true;
          queue<pair<P, int> > que;
          que.push(make_pair(P(i, j), 0));
          while (!que.empty()) {
            P p = que.front().first;
            int d = que.front().second;
            que.pop();
            if (p.first == k && p.second == l) {
              ans = max(ans, d);
              break;
            }
            for (int m = 0; m < (int)(4); m++) {
              int nx = p.first + dx[m];
              int ny = p.second + dy[m];
              if (0 <= nx && nx < h && 0 <= ny && ny < w &&
                  maze[nx][ny] == '.') {
                que.push(make_pair(P(nx, ny), d + 1));
              }
            }
          }
        }
      }
    }
  }
  cout << (ans) << endl;
}
