#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
vector<vector<int>> clr(21, vector<int>(21));
int add = 10000;
void search(int x, int y, int count, vector<vector<int>> map, int goalx,
            int goaly, int res) {
  vector<vector<int>> way = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
  map[y][x] = 2;
  for (auto& i : way)
    if (map[y + i.at(0)][x + i.at(1)] == 0)
      search(x + i.at(1), y + i.at(0), count + 1, map, goalx, goaly, res);
  if (y == goaly && x == goalx) {
    res = min(res, count);
    if (res == count) {
      int sum = 0;
      for (auto& i : map) {
        for (auto& j : i) {
          if (j == 2) sum++;
        }
      }
      add = min(add, sum - 1);
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<vector<int>> map(h + 2, vector<int>(w + 2));
  for (long long i = 0; i < h + 2; i++)
    for (long long j = 0; j < w + 2; j++) map[i][j] = 1;
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) {
      char tmp;
      cin >> tmp;
      if (tmp == '.') map[i + 1][j + 1] = 0;
    }
  vector<int> last(1);
  for (long long i = 1; i < h + 1; i++) {
    for (long long j = 1; j < w + 1; j++) {
      if (map[i][j] == 1) continue;
      for (long long k = 1; k < h + 1; k++) {
        for (long long l = 1; l < w + 1; l++) {
          if (map[k][l] == 1) continue;
          search(j, i, 0, map, l, k, 99999);
          last.push_back(add);
          add = 10000;
        }
      }
    }
  }
  int max = *max_element(last.begin(), last.end());
  cout << max << endl;
  return 0;
}
