#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long int LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
signed main() {
  int r, c;
  cin >> r >> c;
  int sy, sx, gy, gx;
  string C[r];
  for (int i = 0; i < (int)(r); i++) cin >> C[i];
  int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  int visited[r][c];
  int ans = 0;
  for (int i = 0; i < (int)(r); i++) {
    for (int j = 0; j < (int)(c); j++) {
      for (int k = 0; k < (int)(r); k++) {
        for (int l = 0; l < (int)(c); l++) {
          if (C[i][j] == '#' || C[k][l] == '#') continue;
          memset(visited, INF, sizeof(visited));
          sy = i;
          sx = j;
          gy = k;
          gx = l;
          queue<vector<int> > q;
          vector<int> s;
          s.push_back(sy);
          s.push_back(sx);
          s.push_back(0);
          q.push(s);
          visited[sy][sx] = 0;
          while (!q.empty()) {
            vector<int> p = q.front();
            int y = p[0], x = p[1], cnt = p[2];
            q.pop();
            cnt++;
            for (int m = 0; m < (int)(4); m++) {
              int ny = y + dy[m], nx = x + dx[m];
              if (nx < 0 || nx >= c || ny < 0 || ny >= r) continue;
              if (visited[ny][nx] <= cnt) continue;
              if (C[ny][nx] == '.') {
                vector<int> ad;
                ad.push_back(ny);
                ad.push_back(nx);
                ad.push_back(cnt);
                q.push(ad);
                visited[ny][nx] = cnt;
              }
              if (nx == gx && ny == gy) {
                ans = (((ans) < (cnt)) ? (cnt) : (ans));
                break;
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
