#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const long long INF = 1000000000;
queue<pair<int, int>> q;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  int max_ans = 0;
  for (int y = 0; y < (int)(H); y++) {
    for (int x = 0; x < (int)(W); x++) {
      cin >> S[y][x];
    }
  }
  for (int y_s = 0; y_s < (int)(H); y_s++) {
    for (int x_s = 0; x_s < (int)(W); x_s++) {
      for (int y_g = 0; y_g < (int)(H); y_g++) {
        for (int x_g = 0; x_g < (int)(W); x_g++) {
          vector<vector<long long>> d(H, vector<long long>(W, INF));
          pair<int, int> start = {y_s, x_s};
          pair<int, int> goal = {y_g, x_g};
          queue<pair<int, int>> que;
          que.push(start);
          d[start.first][start.second] = 0;
          while (que.size()) {
            pair<int, int> p = que.front();
            que.pop();
            if (p.first == goal.first && p.second == goal.second) {
              break;
            }
            for (int i = 0; i < 4; i++) {
              int ny = p.first + dy[i], nx = p.second + dx[i];
              if (0 <= nx && nx < W && 0 <= ny && ny < H && S[ny][nx] != '#' &&
                  d[ny][nx] == INF) {
                que.push({ny, nx});
                d[ny][nx] = d[p.first][p.second] + 1;
              }
            }
          }
          int ans = d[goal.first][goal.second];
          if (ans > max_ans && ans != INF) {
            max_ans = ans;
          };
        }
      }
    }
  }
  cout << max_ans << endl;
  return 0;
}
