#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const long long INFL = 9 * 1e18;
long long inline digit(long long num) {
  int tmp = 0;
  while (num) {
    tmp++;
    num /= 10;
  }
  return tmp;
}
template <typename T>
inline T digitSum(T num) {
  T sum = 0;
  while (num) {
    sum += num % 10;
    num /= 10;
  }
  return sum;
}
template <typename T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  T g = gcd(a, b);
  return a / g * b;
}
template <typename T>
inline T power(T a, T b) {
  T tmp = 1;
  for (int i = 0; i < ((int)(b)); ++i) {
    tmp *= a;
  }
  return tmp;
}
int ctoi(char c) { return c - '0'; }
bool isOk(long long key, long long value) { return key >= value; }
long long binary_search(vector<long long> a, long long key) {
  long long ok = a.size() - 1;
  long long ng = 0;
  while (abs(ok - ng) > 1) {
    long long mid = (ok + ng) / 2;
    if (isOk(key, a[mid]))
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}
bool isPrime(long long n) {
  for (int i = 2; n >= i * i; ++i) {
    if (!(n % i)) return false;
  }
  return true;
}
vector<long long> primes(long long n) {
  vector<long long> v;
  for (long long i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      n /= i;
      v.push_back(i);
    }
  }
  if (n != 1) v.push_back(n);
  return v;
}
using namespace std;
pair<int, int> operator+(const pair<int, int> &lhs, const pair<int, int> &rhs) {
  pair<int, int> p = {lhs.first + rhs.first, lhs.second + rhs.second};
  return p;
}
bool operator==(const pair<int, int> &lhs, const pair<int, int> &rhs) {
  return (lhs.first == rhs.first) && (lhs.second == rhs.second);
}
bool is_in_field(int col, int row, const pair<int, int> &point) {
  const int c = point.second;
  const int r = point.first;
  return (0 <= c && c < col) && (0 <= r && r < row);
}
int solve(int col, int row, vector<string> &field, const pair<int, int> &start,
          const pair<int, int> &goal) {
  vector<vector<int>> memo;
  for (int i = 0; i < row; ++i) {
    vector<int> v(col, 0);
    memo.push_back(v);
  }
  const pair<int, int> points[] = {
      {-1, 0},
      {1, 0},
      {0, -1},
      {0, 1},
  };
  queue<pair<int, int>> q;
  q.push(start);
  while (!q.empty()) {
    pair<int, int> cur = q.front();
    q.pop();
    if (cur == goal) {
      return memo[cur.second][cur.first];
    }
    for (const auto &point : points) {
      pair<int, int> next = cur + point;
      if (is_in_field(col, row, next)) {
        const char s = field[next.second][next.first];
        if (s == '.') {
          if (memo[next.second][next.first] == 0) {
            q.push(next);
            memo[next.second][next.first] = memo[cur.second][cur.first] + 1;
          }
        }
      }
    }
  }
  return -1;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < ((int)(h)); ++i) cin >> s[i];
  int ans = 0;
  for (int y = 0; y < ((int)(h)); ++y) {
    for (int x = 0; x < ((int)(w)); ++x) {
      vector<vector<int>> a(h, vector<int>(w, 0));
      for (int i = 0; i < ((int)(h)); ++i) {
        for (int j = 0; j < ((int)(w)); ++j) {
          ans = max(solve(h, w, s, make_pair(y, x), make_pair(i, j)), ans);
        }
      }
    }
  }
  cout << (ans) << endl;
  return 0;
}
