#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  for (int i = 0, i_len = ((int)v.size()); i < i_len; ++i) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}
template <typename T, size_t S>
void printArray(const T (&array)[S]) {
  for (auto val : array) std::cout << val << ", ";
  std::cout << "\n";
}
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
const double PI = acos(-1);
const long long MOD = 1000000007;
using Graph = vector<vector<int>>;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
long long h, w;
void bfs(vector<string> &vs, vector<vector<long long>> &seen,
         pair<long long, long long> st, pair<long long, long long> go,
         queue<pair<long long, long long>> que) {
  long long y = que.front().first, x = que.front().second;
  que.pop();
  if (y == go.first && x == go.second) {
    return;
  }
  long long ncnt = seen[y][x];
  for (int i = 0; i < 4; i++) {
    long long ny = y + dy[i], nx = x + dx[i];
    if (0 <= ny && ny < h && 0 <= nx && nx < w) {
      if (vs[ny][nx] == '.' && seen[ny][nx] == -1) {
        seen[ny][nx] = ncnt + 1;
        que.push({ny, nx});
      }
    }
  }
  bfs(vs, seen, st, go, que);
}
void solve() {
  cin >> h >> w;
  vector<string> vs;
  for (int i = 0, i_len = (h); i < i_len; ++i) {
    string s;
    cin >> s;
    vs.push_back(s);
  }
  long long res = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      for (long long k = 0; k < h; k++) {
        for (long long l = 0; l < w; l++) {
          if (vs[i][j] == '.' && vs[k][l] == '.') {
            vector<vector<long long>> seen(h, vector<long long>(w, -1));
            pair<long long, long long> st = {i, j}, go = {k, l};
            queue<pair<long long, long long>> que;
            seen[st.first][st.second] = 0;
            que.push(st);
            bfs(vs, seen, st, go, que);
            res = max(res, seen[go.first][go.second]);
          }
        }
      }
    }
  }
  cout << res << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}
