#include <bits/stdc++.h>
using namespace std;
template <class T>
void printvec(const vector<T>& v) {
  for (auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}
template <class T>
void printtree(const vector<vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": ";
    printvec(tree[i]);
  }
}
template <class T, class U>
void printmap(const map<T, U>& mp) {
  for (auto x : mp) {
    cout << x.first << "=>" << x.second << endl;
  }
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1e9;
const long long MOD = 1000000007;
int dr[4] = {1, -1, 0, 0};
int dc[4] = {0, 0, 1, -1};
int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  long long h, w;
  cin >> h >> w;
  vector<string> maze(h);
  for (long long r = 0; r < h; ++r) {
    cin >> maze[r];
  }
  vector<vector<long long> > d(h * w, vector<long long>(h * w, INF));
  for (long long r = 0; r < h; ++r) {
    for (long long c = 0; c < w; ++c) {
      if (maze[r][c] == '#') {
        continue;
      }
      for (long long i = 0; i < 4; ++i) {
        int nextR = r + dr[i];
        int nextC = c + dc[i];
        if (nextR < 0 || nextR >= h || nextC < 0 || nextC >= w) {
          continue;
        }
        if (maze[nextR][nextC] == '#') {
          continue;
        }
        d[r * w + c][nextR * w + nextC] = 1;
      }
    }
  }
  for (long long k = 0; k < h * w; ++k) {
    for (long long i = 0; i < h * w; ++i) {
      for (long long j = 0; j < h * w; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < h * w; ++i) {
    for (long long j = 0; j < h * w; ++j) {
      if (d[i][j] != INF) {
        ans = max(ans, d[i][j]);
      }
    }
  }
  cout << ans << endl;
}
