#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <int>
ostream& operator<<(ostream& os, const vector<int>& v) {
  os << "[";
  for (int i = 0; i < v.size(); ++i) {
    if (v[i] != 1000000001)
      os << v[i];
    else
      os << "INF";
    if (i != v.size() - 1) os << ", ";
  }
  os << "]\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  for (int i = 0; i < v.size(); ++i) {
    os << v[i];
    ;
    if (i != v.size() - 1) os << ", ";
  }
  os << "]\n";
  return os;
}
const int N = 21;
vector<string> v(N);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
bool check(int i, int j, int n, int m) {
  if (i < 0 || j < 0 || i >= n || j >= m || v[i][j] == '#') return false;
  return true;
}
int bfs(pair<int, int> start, pair<int, int> end, int n, int m) {
  queue<pair<int, int> > q;
  q.push(start);
  pair<int, int> null = make_pair(-1, -1);
  q.push(null);
  vector<vector<bool> > vis(21, vector<bool>(21));
  int dist = 0;
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    if (u == null) {
      if (q.empty()) break;
      dist++;
      q.push(null);
    }
    for (int k = 0; k < 4; k++) {
      int x = u.first + dx[k];
      int y = u.second + dy[k];
      if (check(x, y, n, m) && !vis[x][y]) {
        q.push(make_pair(x, y));
        vis[x][y] = true;
      }
    }
  }
  return dist;
}
int main() {
  {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  };
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int max1 = 0;
  for (int a = 0; a < n; a++) {
    for (int b = 0; b < m; b++) {
      for (int c = 0; c < n; c++) {
        for (int d = 0; d < m; d++) {
          if (check(a, b, n, m) && check(c, d, n, m) &&
              (make_pair(a, b) <= make_pair(c, d))) {
            max1 = max(max1, bfs(make_pair(a, b), make_pair(c, d), n, m));
          }
        }
      }
    }
  }
  cout << max1 << endl;
  return 0;
}
