#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool compare(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) {
    return a.first < b.first;
  } else {
    return a.second < b.second;
  }
}
bool In_map(long long y, long long x, long long h, long long w) {
  if (y < 0 || x < 0 || y >= h || x >= w) {
    return 0;
  } else {
    return 1;
  }
}
const vector<long long> dx{1, 0, -1, 0};
const vector<long long> dy{0, 1, 0, -1};
int main() {
  long long H, W;
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      cin >> S[i][j];
    }
  }
  long long ans = 0;
  for (int sy = 0; sy < (H); sy++) {
    for (int sx = 0; sx < (W); sx++) {
      for (int gy = 0; gy < (H); gy++) {
        for (int gx = 0; gx < (W); gx++) {
          vector<vector<long long>> dist(H, vector<long long>(W, -1));
          queue<pair<long long, long long>> que;
          long long dis = 0;
          dist[sy][sx] = 0;
          que.push(make_pair(sy, sx));
          while (!que.empty()) {
            pair<long long, long long> v = que.front();
            que.pop();
            if (v.first == gy && v.second == gx) {
              dis = dist[v.first][v.second];
              break;
            }
            for (int dir = 0; dir < (4); dir++) {
              long long ny = v.first + dy[dir];
              long long nx = v.second + dx[dir];
              if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
              if (S[ny][nx] == '#') continue;
              if (dist[ny][nx] != -1) continue;
              dist[ny][nx] = dist[v.first][v.second] + 1;
              que.push(make_pair(ny, nx));
            }
          }
          chmax(ans, dis);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
