#include <bits/stdc++.h>
using namespace std;
long long N;
long long M;
vector<vector<long long>> data(22, vector<long long>(22));
long long dfs(long long d, long long x, long long y,
              vector<vector<long long>> map) {
  long long xx, yy;
  d++;
  xx = x + 1;
  yy = y;
  if ((xx >= 0) && (xx < M) && (yy >= 0) && (yy < N)) {
    if ((data[xx][yy] == 0) && (map[xx][yy] == 0)) {
      map[xx][yy] = 1;
      long long buf = dfs(d, xx, yy, map);
      map[xx][yy] = 0;
      d = ((d) > (buf) ? (d) : (buf));
    }
  }
  xx = x - 1;
  yy = y;
  if ((xx >= 0) && (xx < M) && (yy >= 0) && (yy < N)) {
    if ((data[xx][yy] == 0) && (map[xx][yy] == 0)) {
      map[xx][yy] = 1;
      long long buf = dfs(d, xx, yy, map);
      map[xx][yy] = 0;
      d = ((d) > (buf) ? (d) : (buf));
    }
  }
  xx = x;
  yy = y + 1;
  if ((xx >= 0) && (xx < M) && (yy >= 0) && (yy < N)) {
    if ((data[xx][yy] == 0) && (map[xx][yy] == 0)) {
      map[xx][yy] = 1;
      long long buf = dfs(d, xx, yy, map);
      map[xx][yy] = 0;
      d = ((d) > (buf) ? (d) : (buf));
    }
  }
  xx = x;
  yy = y - 1;
  if ((xx >= 0) && (xx < M) && (yy >= 0) && (yy < N)) {
    if ((data[xx][yy] == 0) && (map[xx][yy] == 0)) {
      map[xx][yy] = 1;
      long long buf = dfs(d, xx, yy, map);
      map[xx][yy] = 0;
      d = ((d) > (buf) ? (d) : (buf));
    }
  }
  return d;
}
int main() {
  cin >> N;
  cin >> M;
  for (long long(i) = long long(0); (i) < long long(N); (i)++) {
    string s;
    cin >> s;
    for (long long(j) = long long(0); (j) < long long(M); (j)++) {
      if (s[j] == '#') {
        data[i][j] = 1;
      } else {
        data[i][j] = 0;
      }
    }
  }
  long long ans = 0;
  for (long long(i) = long long(0); (i) < long long(N); (i)++) {
    for (long long(j) = long long(0); (j) < long long(M); (j)++) {
      vector<vector<long long>> map(N, vector<long long>(M));
      queue<pair<long long, pair<long long, long long>>> q;
      pair<long long, pair<long long, long long>> buf;
      buf.first = 0;
      buf.second.first = i;
      buf.second.second = j;
      q.push(buf);
      map[i][j] = 1;
      long long bufans = 0;
      while (q.size() != 0) {
        pair<long long, pair<long long, long long>> now = q.front();
        q.pop();
        long long x, y;
        x = now.second.first;
        y = now.second.second;
        long long xx, yy;
        pair<long long, pair<long long, long long>> bb;
        bufans = ((bufans) > (now.first) ? (bufans) : (now.first));
        if ((i == 2) && (j == 0)) {
        }
        xx = x + 1;
        yy = y;
        if ((xx >= 0) && (xx < N) && (yy >= 0) && (yy < M)) {
          if ((data[xx][yy] == 0) && (map[xx][yy] == 0)) {
            map[xx][yy] = 1;
            bb.first = now.first + 1;
            bb.second.first = xx;
            bb.second.second = yy;
            q.push(bb);
          }
        }
        xx = x - 1;
        yy = y;
        if ((xx >= 0) && (xx < N) && (yy >= 0) && (yy < M)) {
          if ((data[xx][yy] == 0) && (map[xx][yy] == 0)) {
            map[xx][yy] = 1;
            bb.first = now.first + 1;
            bb.second.first = xx;
            bb.second.second = yy;
            q.push(bb);
          }
        }
        xx = x;
        yy = y + 1;
        if ((xx >= 0) && (xx < N) && (yy >= 0) && (yy < M)) {
          if ((data[xx][yy] == 0) && (map[xx][yy] == 0)) {
            map[xx][yy] = 1;
            bb.first = now.first + 1;
            bb.second.first = xx;
            bb.second.second = yy;
            q.push(bb);
          }
        }
        xx = x;
        yy = y - 1;
        if ((xx >= 0) && (xx < N) && (yy >= 0) && (yy < M)) {
          if ((data[xx][yy] == 0) && (map[xx][yy] == 0)) {
            map[xx][yy] = 1;
            bb.first = now.first + 1;
            bb.second.first = xx;
            bb.second.second = yy;
            q.push(bb);
          }
        }
      }
      ans = ((ans) > (bufans) ? (ans) : (bufans));
    }
  }
  cout << (ans) << endl;
  return 0;
}
