#include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1>
ostream &operator<<(ostream &out, pair<T, T1> obj) {
  out << "(" << obj.first << ", " << obj.second << ")";
  return out;
}
template <typename T, typename T1>
ostream &operator<<(ostream &out, map<T, T1> cont) {
  typename map<T, T1>::const_iterator itr = cont.begin();
  typename map<T, T1>::const_iterator ends = cont.end();
  for (; itr != ends; ++itr) {
    out << *itr << " ";
  }
  out << endl;
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, set<T> cont) {
  typename set<T>::const_iterator itr = cont.begin();
  typename set<T>::const_iterator ends = cont.end();
  for (; itr != ends; ++itr) {
    out << *itr << " ";
  }
  out << endl;
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, multiset<T> cont) {
  typename multiset<T>::const_iterator itr = cont.begin();
  typename multiset<T>::const_iterator ends = cont.end();
  for (; itr != ends; ++itr) {
    out << *itr << " ";
  }
  out << endl;
  return out;
}
template <typename T,
          template <typename ELEM, typename ALLOC = allocator<ELEM>> class CONT>
ostream &operator<<(ostream &out, CONT<T> cont) {
  typename CONT<T>::const_iterator itr = cont.begin();
  typename CONT<T>::const_iterator ends = cont.end();
  for (; itr != ends; ++itr) {
    out << *itr << " ";
  }
  out << endl;
  return out;
}
template <typename T, unsigned int N, typename CTy, typename CTr>
typename enable_if<!is_same<T, char>::value, basic_ostream<CTy, CTr> &>::type
operator<<(basic_ostream<CTy, CTr> &out, const T (&arr)[N]) {
  for (auto i = 0; i < N; ++i) {
    out << arr[i] << " ";
  }
  out << endl;
  return out;
}
template <typename T>
T GCD(T a, T b) {
  T min_v = min(a, b);
  T max_v = max(a, b);
  while (min_v) {
    T temp = max_v % min_v;
    max_v = min_v;
    min_v = temp;
  }
  return max_v;
}
template <typename T>
T LCM(T a, T b) {
  return (a * b) / gcd(a, b);
}
template <typename T>
T fastExpPow(T base, T exp, T mod) {
  T res = 1;
  while (exp) {
    if (exp & 1) {
      res *= base;
      res %= mod;
    }
    exp >>= 1;
    base *= base;
    base %= mod;
  }
  return res % mod;
}
int H, W, answer;
int distances[30][30];
int dr[] = {0, 0, 1, -1}, dc[] = {1, -1, 0, 0};
char board[30][30];
void bfs(int initR, int initC) {
  queue<pair<int, pair<int, int>>> que;
  memset(distances, -1, sizeof(distances));
  que.push(make_pair(0, make_pair(initR, initC)));
  distances[initR][initC] = 0;
  while (!que.empty()) {
    int d = que.front().first;
    int r = que.front().second.first;
    int c = que.front().second.second;
    que.pop();
    for (auto i = 0; i < 4; ++i) {
      int newR = r + dr[i];
      int newC = c + dc[i];
      int newD = d + 1;
      if (newR >= 1 && newR <= H && newC >= 1 && newC <= W &&
          board[newR][newC] == '.' && distances[newR][newC] == -1) {
        que.push(make_pair(newD, make_pair(newR, newC)));
        distances[newR][newC] = newD;
        answer = max(answer, distances[newR][newC]);
      }
    }
  }
}
int main() {
  scanf("%d%d", &H, &W);
  for (auto i = 1; i <= H; ++i) {
    for (auto j = 1; j <= W; ++j) {
      scanf(" %c", &board[i][j]);
    }
  }
  for (auto i = 1; i <= H; ++i) {
    for (auto j = 1; j <= W; ++j) {
      bfs(i, j);
    }
  }
  printf("%d\n", answer);
  return 0;
}
