#include <bits/stdc++.h>
using namespace std;
void RI() {}
template <typename... T>
void RI(int& head, T&... tail) {
  scanf("%d", &head);
  RI(tail...);
}
template <typename T>
void _dump(const char* s, T&& head) {
  cerr << s << "=" << head << endl;
}
template <typename T, typename... Args>
void _dump(const char* s, T&& head, Args&&... tail) {
  int c = 0;
  while (*s != ',' || c != 0) {
    if (*s == '(' || *s == '[' || *s == '{') c++;
    if (*s == ')' || *s == ']' || *s == '}') c--;
    cerr << *s++;
  }
  cerr << "=" << head << ", ";
  _dump(s + 1, tail...);
}
template <typename Iter>
ostream& _out(ostream& s, Iter b, Iter e) {
  s << "[";
  for (auto it = b; it != e; it++) s << (it == b ? "" : " ") << *it;
  s << "]";
  return s;
}
template <typename A, typename B>
ostream& operator<<(ostream& s, const pair<A, B>& p) {
  return s << "(" << p.first << "," << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& c) {
  return _out(s, begin(c), end(c));
}
template <typename T>
ostream& operator<<(ostream& s, const set<T>& c) {
  return _out(s, begin(c), end(c));
}
template <typename A, typename B>
ostream& operator<<(ostream& s, const map<A, B>& c) {
  return _out(s, begin(c), end(c));
}
const int MAX_N = 25;
const int Z = 1e9;
int n, m, ans = 0;
vector<string> B;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int solve(int a, int b) {
  int sx = a / m, sy = a % m;
  int tx = b / m, ty = a % m;
  queue<pair<int, int> > q;
  bool vis[MAX_N][MAX_N] = {};
  vis[sx][sy] = true;
  q.push({sx, sy});
  int d = 0;
  while (!q.empty()) {
    int sz = q.size();
    for (int k = 0; k < sz; k++) {
      int x = q.front().first, y = q.front().second;
      q.pop();
      if (x == tx && y == ty) return d;
      for (int i = 0; i < 4; i++) {
        int xx = x + dx[i];
        int yy = y + dy[i];
        if (0 <= xx && xx < n && 0 <= yy && yy < m && B[xx][yy] != '#' &&
            !vis[xx][yy]) {
          q.push({xx, yy});
          vis[xx][yy] = true;
        }
      }
    }
    d++;
  }
  return d - 1;
}
int main(int argc, char* argv[]) {
  RI(n, m);
  for (int i = 0; i < (int)(n); i++) {
    string s;
    cin >> s;
    B.push_back(s);
  }
  for (int i = 0; i < (int)(n * m); i++) {
    for (int j = (int)(i + 1); j <= (int)(n * m); j++) {
      if (B[i][j] != '#') {
        ans = max(ans, solve(i, j));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
