#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
char space[maxn][maxn];
int rwp[maxn], lep[maxn];
int n, m, sum0;
double ans;
void readin() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", space[i]);
}
void get_pos() {
  memset(rwp, -1, sizeof(rwp));
  memset(lep, -1, sizeof(lep));
  sum0 = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (space[i][j] == 'X') rwp[i] = j, lep[j] = i, ++sum0;
  sum0 = n * m - sum0;
  ans = 0;
  for (int i = 0; i < m; ++i) {
    int now = n;
    if (lep[i] != -1) --now;
    for (int j = 0; j < m; ++j)
      if (lep[j] != -1)
        ans += 1.0 * now * (n - 1) * abs(i - j);
      else
        ans += 1.0 * now * n * abs(i - j);
  }
  for (int i = 0; i < n; ++i) {
    int now = m;
    if (rwp[i] != -1) --now;
    for (int j = 0; j < n; ++j)
      if (rwp[j] != -1)
        ans += 1.0 * now * (m - 1) * abs(i - j);
      else
        ans += 1.0 * now * m * abs(i - j);
  }
}
void work_row() {
  for (int i = 0, tot = 0; i < n; ++i) {
    if (rwp[i] == -1) {
      tot = 0;
      continue;
    }
    if (i == 0 || rwp[i] > rwp[i - 1])
      tot += rwp[i];
    else
      tot = rwp[i];
    ans += 4.0 * tot * (m - rwp[i] - 1);
  }
  for (int i = n - 1, tot = 0; i >= 0; --i) {
    if (rwp[i] == -1) {
      tot = 0;
      continue;
    }
    if (i == n - 1 || rwp[i] > rwp[i + 1])
      tot += rwp[i];
    else
      tot = rwp[i];
    ans += 4.0 * tot * (m - rwp[i] - 1);
  }
  for (int i = 0; i < n; ++i)
    if (rwp[i] != -1) ans -= 4.0 * rwp[i] * (m - rwp[i] - 1);
}
void work_line() {
  for (int i = 0, tot = 0; i < m; ++i) {
    if (lep[i] == -1) {
      tot = 0;
      continue;
    }
    if (i == 0 || lep[i] > lep[i - 1])
      tot += lep[i];
    else
      tot = lep[i];
    ans += 4.0 * tot * (n - lep[i] - 1);
  }
  for (int i = m - 1, tot = 0; i >= 0; --i) {
    if (lep[i] == -1) {
      tot = 0;
      continue;
    }
    if (i == m - 1 || lep[i] > lep[i + 1])
      tot += lep[i];
    else
      tot = lep[i];
    ans += 4.0 * tot * (n - lep[i] - 1);
  }
  for (int i = 0; i < m; ++i)
    if (lep[i] != -1) ans -= 4.0 * lep[i] * (n - lep[i] - 1);
}
int main() {
  readin();
  get_pos();
  work_row();
  work_line();
  printf("%.9lf\n", ans / (1.0 * sum0 * sum0));
  return 0;
}
