#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
const int INF = (1 << 30) - 1;
const int64 INF64 = (1LL << 62) - 1;
template <typename T>
T gcd(T a, T b) {
  if (a < b) return gcd(b, a);
  T r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
template <typename T>
T lcm(const T a, const T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b)
    return a = b, true;
  else
    return false;
}
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b)
    return a = b, true;
  else
    return false;
}
char buf[10000000];
int bufi = 0;
template <typename T>
void readi(T &n) {
  bool negative = false;
  if (buf[bufi] == '-') negative = true, bufi++, readui(n);
  if (negative) n = -n;
}
template <typename T>
void readui(T &n) {
  n = 0;
  int c = buf[bufi++];
  for (; '0' <= c && c <= '9'; c = buf[bufi++]) n = 10 * n + c - '0';
}
template <typename T>
void readf(T &x) {
  bool negative = false;
  if (buf[bufi] == '-') negative = true, bufi++, readuf(x);
  if (negative) x = -x;
}
template <typename T>
void readuf(T &x) {
  x = 0;
  T y = 0;
  int z = 0;
  int c = buf[bufi++];
  for (; '0' <= c && c <= '9'; c = buf[bufi++]) x = 10 * x + c - '0';
  if (buf[bufi - 1] == '.')
    for (; '0' <= c && c <= '9'; c = buf[bufi++], ++z) y = 10 * y + c - '0';
  x += y / pow(10, z);
}
void reads(string &s) {
  const int begin = bufi;
  int c;
  while (c = buf[bufi++], c != ' ' && c != '\n') {
  }
  s = string(buf + begin, buf + bufi);
}
void readline(string &s) {
  const int begin = bufi;
  while (buf[bufi++] != '\n') {
  }
  s = string(buf + begin, buf + bufi);
}
constexpr int dx[] = {1, 0, 0, -1};
constexpr int dy[] = {0, 1, -1, 0};
int main() {
  cout << fixed << setprecision(15);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin.read(buf, sizeof buf);
  int h, w;
  readui(h), readui(w);
  bool maze[22][22] = {};
  cin >> h >> w;
  for (int hi = 0; hi < (int)(h); ++hi) {
    for (int wi = 0; wi < (int)(w); ++wi)
      maze[hi + 1][wi + 1] = buf[bufi++] == '.';
    bufi++;
  }
  int d[22][22];
  int ans = 0;
  queue<pair<char, char>> bfs;
  for (int hi = 1; hi <= h; ++hi)
    for (int wi = 1; wi <= w; ++wi) {
      memset(d, -1, sizeof d);
      bfs.emplace(make_pair(hi, wi));
      d[hi][wi] = 0;
      while (!bfs.empty()) {
        auto p = bfs.front();
        bfs.pop();
        for (int k = 0; k < (int)(4); ++k) {
          char ny = p.first + dy[k], nx = p.second + dx[k];
          if (maze[ny][nx] && d[ny][nx] == -1) {
            chmax(ans, d[ny][nx] = d[p.first][p.second] + 1);
            bfs.emplace(make_pair(ny, nx));
          }
        }
      }
    }
  cout << (ans) << '\n';
  return 0;
}
