#include <bits/stdc++.h>
const int N = 1005;
int n, m, cnt[N], lb[N], tot = 0;
char s[N][N];
long long sum = 0, pre[N];
int main() {
  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] == '.') ++cnt[i], ++tot;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (s[i][j] == '.') pre[i] += i;
  for (int i = 1; i <= n; ++i) pre[i] += pre[i - 1], cnt[i] += cnt[i - 1];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (s[i][j] == '.') {
        sum += (long long)i * cnt[i] - pre[i];
        sum += pre[n] - pre[i] - (long long)i * (cnt[n] - cnt[i]);
      }
  memset(cnt, 0, sizeof(cnt));
  memset(pre, 0, sizeof(pre));
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (s[i][j] == '.') ++cnt[j];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (s[i][j] == '.') pre[j] += j;
  for (int j = 1; j <= m; ++j) pre[j] += pre[j - 1], cnt[j] += cnt[j - 1];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (s[i][j] == '.') {
        sum += (long long)j * cnt[j] - pre[j];
        sum += pre[m] - pre[j] - (long long)j * (cnt[m] - cnt[j]);
      }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j)
      if (s[i][j] == 'X') {
        lb[i] = j;
        break;
      }
  }
  for (int i = 1; i <= n; ++i) {
    if (!lb[i] || lb[i] == m) continue;
    for (int j = i; j; --j) {
      sum += (long long)2 * (m - lb[i]) * (lb[j] - 1);
      if (lb[j - 1] > lb[j] || !lb[j - 1]) break;
    }
    for (int j = i; j <= n; ++j) {
      if (j > i) sum += (long long)2 * (m - lb[i]) * (lb[j] - 1);
      if (lb[j + 1] > lb[j] || !lb[j + 1]) break;
    }
    for (int j = i; j; --j) {
      sum += (long long)2 * (lb[i] - 1) * (m - lb[j]);
      if (m - lb[j - 1] > m - lb[j] || lb[j - 1] == m) break;
    }
    for (int j = i; j <= n; ++j) {
      if (j > i) sum += (long long)2 * (lb[i] - 1) * (m - lb[j]);
      if (m - lb[j + 1] > m - lb[j] || lb[j + 1] == m) break;
    }
  }
  memset(lb, 0, sizeof(lb));
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= n; ++i)
      if (s[i][j] == 'X') {
        lb[j] = i;
        break;
      }
  }
  for (int i = 1; i <= m; ++i) {
    if (!lb[i] || lb[i] == n) continue;
    for (int j = i; j; --j) {
      sum += (long long)2 * (n - lb[i]) * (lb[j] - 1);
      if (lb[j - 1] > lb[j] || !lb[j - 1]) break;
    }
    for (int j = i; j <= m; ++j) {
      if (j > i) sum += (long long)2 * (n - lb[i]) * (lb[j] - 1);
      if (lb[j + 1] > lb[j] || !lb[j + 1]) break;
    }
    for (int j = i; j; --j) {
      sum += (long long)2 * (lb[i] - 1) * (n - lb[j]);
      if (n - lb[j - 1] > n - lb[j] || lb[j - 1] == n) break;
    }
    for (int j = i; j <= m; ++j) {
      if (j > i) sum += (long long)2 * (lb[i] - 1) * (n - lb[j]);
      if (n - lb[j + 1] > n - lb[j] || lb[j + 1] == n) break;
    }
  }
  printf("%.9lf", (double)sum / tot / tot);
  return 0;
}
