#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  char c[n][m];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> c[i][j];
  bool b[n][m];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) b[i][j] = 0;
  queue<pair<long long, long long> > q;
  long long mx = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (c[i][j] == '.') {
        for (long long i = 0; i < n; i++)
          for (long long j = 0; j < m; j++) b[i][j] = 0;
        while (!q.empty()) q.pop();
        q.push({i, j});
        long long curr_lvl = 1, nxt_lvl = 0;
        long long temp = -1;
        while (!q.empty()) {
          while (curr_lvl > 0) {
            curr_lvl--;
            pair<long long, long long> p = q.front();
            q.pop();
            b[p.first][p.second] = 1;
            if (p.first - 1 >= 0)
              if (b[p.first - 1][p.second] == 0 &&
                  c[p.first - 1][p.second] != '#') {
                q.push({p.first - 1, p.second});
                nxt_lvl++;
              }
            if (p.first + 1 < n)
              if (b[p.first + 1][p.second] == 0 &&
                  c[p.first + 1][p.second] != '#') {
                q.push({p.first + 1, p.second});
                nxt_lvl++;
              }
            if (p.second - 1 >= 0)
              if (b[p.first][p.second - 1] == 0 &&
                  c[p.first][p.second - 1] != '#') {
                q.push({p.first, p.second - 1});
                nxt_lvl++;
              }
            if (p.second + 1 < m)
              if (b[p.first][p.second + 1] == 0 &&
                  c[p.first][p.second + 1] != '#') {
                q.push({p.first, p.second + 1});
                nxt_lvl++;
              }
          }
          curr_lvl = nxt_lvl;
          nxt_lvl = 0;
          temp++;
        }
        mx = max(mx, temp);
      }
    }
  }
  cout << mx << '\n';
}
