#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1100;
char s[MAXN][MAXN];
int r[MAXN], l[MAXN];
int n, m;
long long ans = 0;
long long dp[MAXN][MAXN];
vector<pair<int, int> > st;
int cnt = 0;
int Abs(int a) { return a > 0 ? a : -a; }
int main() {
  memset(r, 0, sizeof(r));
  memset(l, 0, sizeof(l));
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == 'X') {
        cnt++;
        r[i] = j;
        l[j] = i;
        st.push_back(make_pair(i, j));
      }
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i == 1) {
        if (j == 1)
          dp[i][j] = (n + m - 2) * n * m / 2;
        else
          dp[i][j] = dp[i][j - 1] + (j - 1) * n - (m - j + 1) * n;
      } else
        dp[i][j] = dp[i - 1][j] + (i - 1) * m - (n - i + 1) * m;
      if (s[i][j] == '.')
        ans += dp[i][j];
      else
        ans -= dp[i][j];
    }
  }
  for (int i = 0; i < st.size(); i++) {
    for (int j = i + 1; j < st.size(); j++) {
      ans += 2 * Abs(st[i].first - st[j].first);
      ans += 2 * Abs(st[i].second - st[j].second);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (r[i] == 0) continue;
    ans += (r[i] - 1) * (m - r[i]) * 4;
    for (int j = i + 1; j <= n; j++) {
      if (r[j] < r[j - 1]) break;
      ans += (r[i] - 1) * (m - r[j]) * 4;
    }
    for (int j = i - 1; j > 0; j--) {
      if (r[j] < r[j + 1]) break;
      ans += (r[i] - 1) * (m - r[j]) * 4;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (l[i] == 0) continue;
    ans += (l[i] - 1) * (n - l[i]) * 4;
    for (int j = i + 1; j <= m; j++) {
      if (l[j] < l[j - 1]) break;
      ans += (l[i] - 1) * (n - l[j]) * 4;
    }
    for (int j = i - 1; j > 0; j--) {
      if (l[j] < l[j + 1]) break;
      ans += (l[i] - 1) * (n - l[j]) * 4;
    }
  }
  long long down = (long long)(n * m - cnt) * (n * m - cnt);
  printf("%.10f\n", (double)ans / down);
  return 0;
}
