#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long m) {
  long long r = 1;
  for (; y; y >>= 1) {
    if (y & 1) r = r * x % m;
    x = x * x % m;
  }
  return r;
}
const long long mod = 1e9 + 7;
const long double pi = 3.14159265358979;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
int h, w, arr[20][20], visited[20][20], level[20][20];
int r[4] = {1, 0, -1, 0};
int c[4] = {0, 1, 0, -1};
int check(int i, int j) {
  if (i >= 0 && j >= 0 && i < h && j < w) return 1;
  return 0;
}
int dfs(int a, int b) {
  int k = 0;
  queue<int> q;
  q.push(a);
  q.push(b);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    int y = q.front();
    q.pop();
    visited[x][y] = 1;
    for (int i = 0; i < 4; i++) {
      if (check(x + r[i], y + c[i]) && arr[x + r[i]][y + c[i]] == 1 &&
          !visited[x + r[i]][y + c[i]]) {
        q.push(x + r[i]);
        q.push(y + c[i]);
        level[x + r[i]][y + c[i]] = level[x][y] + 1;
        k = max(k, level[x + r[i]][y + c[i]]);
      }
    }
  }
  return k;
}
int run_test() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char k;
      cin >> k;
      if (k == '#')
        arr[i][j] = 0;
      else {
        arr[i][j] = 1;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      visited[i][j] = 0;
    }
  }
  int k, p, q, ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (arr[i][j] == 1 && !visited[i][j]) {
        k = dfs(i, j);
        for (p = 0; p < h; p++) {
          for (q = 0; q < w; q++) {
            if (level[p][q] == k) {
              break;
            }
          }
        }
        for (int n = 0; n < h; n++) {
          for (int m = 0; m < w; m++) {
            visited[n][m] = 0;
            level[n][m] = 0;
          }
        }
        k = dfs(p, q);
        ans = max(ans, k);
      }
    }
  }
  cout << ans - 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long t;
  t = 1;
  while (t--) {
    run_test();
  }
}
