#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const long long MOD = 1000000007;
const long long N = 300005;
const long long inf = 10000000000000000;
void print(vector<long long> v) {
  long long i;
  for (i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void print(vector<pair<long long, long long> > v) {
  long long i;
  for (i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second << "\n";
  }
}
vector<long long> read(long long n) {
  long long i;
  vector<long long> arr(n, 0);
  for (i = 0; i < n; i++) cin >> arr[i];
  return arr;
}
vector<long long> read(long long n, long long k) {
  long long i;
  vector<long long> arr(n + k, 0);
  for (i = k; i < n + k; i++) cin >> arr[i];
  return arr;
}
bool isEven(long long n) { return n % 2 == 0; }
bool isOdd(long long n) { return n % 2 != 0; }
long long n, m;
vector<string> str;
long long dp[100][100];
bool vis[100][100];
vector<long long> dx = {-1, 0, 0, 1};
vector<long long> dy = {0, -1, 1, 0};
bool isVal(long long i, long long j) {
  return (0 <= i && i < n && 0 <= j && j < m);
}
void dfs(long long x, long long y) {
  if (!isVal(x, y)) {
    return;
  }
  if (str[x][y] == '#') return;
  vis[x][y] = true;
  long long i;
  for (i = 0; i < 4; i++) {
    if (isVal(x + dx[i], y + dy[i]) && !vis[x + dx[i]][y + dy[i]] &&
        str[x + dx[i]][y + dy[i]] != '#') {
      dp[x + dx[i]][y + dy[i]] = dp[x][y] + 1;
      dfs(x + dx[i], y + dy[i]);
    }
  }
}
void bfs(long long x1, long long y1) {
  queue<pair<long long, long long> > q;
  dp[x1][y1] = 0;
  long long i, x, y;
  q.push({x1, y1});
  while (!q.empty()) {
    pair<long long, long long> next = q.front();
    q.pop();
    x = next.first, y = next.second;
    vis[x][y] = true;
    for (i = 0; i < 4; i++) {
      if (isVal(x + dx[i], y + dy[i]) && !vis[x + dx[i]][y + dy[i]] &&
          str[x + dx[i]][y + dy[i]] != '#') {
        dp[x + dx[i]][y + dy[i]] = dp[x][y] + 1;
        q.push({x + dx[i], y + dy[i]});
      }
    }
  }
}
void solve() {
  long long t = 1;
  while (t--) {
    long long i, j, k, p, q, x, y, a, b, l, r;
    cin >> n >> m;
    for (i = 0; i < n; i++) {
      string s;
      cin >> s;
      str.push_back(s);
    }
    long long ans = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (str[i][j] == '.') {
          for (x = 0; x < n; x++) {
            for (y = 0; y < m; y++) {
              dp[x][y] = -1;
              vis[x][y] = false;
            }
          }
          dp[i][j] = 0;
          bfs(i, j);
          long long mx = -1;
          for (x = 0; x < n; x++) {
            for (y = 0; y < m; y++) {
              mx = max(mx, dp[x][y]);
            }
          }
          ans = max(ans, mx);
        }
      }
    }
    cout << ans;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  auto start = high_resolution_clock::now();
  solve();
  long long i, j, k, n, m, p, q, x, y, a, b, l, r;
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start);
  return 0;
}
