#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  long long l = v.size();
  for (long long i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, set<T> const& v) {
  for (auto i = v.begin(); i != v.end(); i++) out << (*i) << ' ';
  return out;
}
template <typename T, typename V>
ostream& operator<<(ostream& out, map<T, V> const& v) {
  for (auto i = v.begin(); i != v.end(); i++)
    out << "\n" << (i->first) << ":" << (i->second);
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
const long long N = 500;
long long h, w;
vector<string> arr;
long long graph[500][500];
long long shortest_path[500][500];
long long n;
void floyd_warshall() {
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      shortest_path[i][j] = graph[i][j];
    }
  }
  for (long long k = 0; k < n; k++) {
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < n; j++) {
        if (shortest_path[i][k] + shortest_path[k][j] < shortest_path[i][j]) {
          shortest_path[i][j] = shortest_path[i][k] + shortest_path[k][j];
        }
      }
    }
  }
}
long long mx[] = {1, -1, 0, 0};
long long my[] = {0, 0, 1, -1};
long long getnode(long long x, long long y) {
  long long ans = (x * w + y);
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> h >> w;
  for (long long i = 0; i < h; i++) {
    string temp;
    cin >> temp;
    arr.push_back(temp);
  }
  n = h * w;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      graph[i][j] = 1000000000000000001;
    }
  }
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (arr[i][j] == '#') continue;
      for (long long k = 0; k < 4; k++) {
        long long tx = i + mx[k], ty = j + my[k];
        if (tx < h && tx >= 0 && ty < w && ty >= 0 && arr[tx][ty] == '.') {
          long long a = getnode(tx, ty);
          long long b = getnode(i, j);
          graph[a][b] = 1;
          graph[b][a] = 1;
        }
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      shortest_path[i][j] = 1000000000000000001;
    }
  }
  floyd_warshall();
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (shortest_path[i][j] != 1000000000000000001) {
        ans = max(ans, shortest_path[i][j]);
      }
    }
  }
  cout << ans << "\n";
}
