#include <bits/stdc++.h>
const int MAXV = 1005;
long long n, m, leftB[MAXV][2], upperB[MAXV][2];
using namespace std;
long long dist() {
  long long ysum = 0, ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) ysum += abs(i - j);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) ans += abs(i - j) * n * n + ysum;
  return ans;
}
long long dist(int str, int stb) {
  long long ysum = 0, ans = 0;
  for (int i = 0; i < n; i++) ysum += abs(str - i);
  for (int i = 0; i < m; i++) ans += abs(i - stb) * n + ysum;
  return ans;
}
long long calc() {
  for (int i = 1; i <= m; i++)
    if (upperB[i][0]) {
      int lst;
      upperB[i][1] += (upperB[i][0] - 1) * (n - upperB[i][0]) * 2 * 2;
      lst = upperB[i][0];
      for (int j = i + 1; j <= m; j++)
        if (upperB[j][0] && upperB[j][0] > lst) {
          upperB[i][1] += (upperB[i][0] - 1) * (n - upperB[j][0]) * 2;
          lst = upperB[j][0];
        } else
          break;
      lst = upperB[i][0];
      for (int j = i + 1; j <= m; j++)
        if (upperB[j][0] && upperB[j][0] < lst) {
          upperB[i][1] += (n - upperB[i][0]) * (upperB[j][0] - 1) * 2;
          lst = upperB[j][0];
        } else
          break;
      lst = upperB[i][0];
      for (int j = i - 1; j > 0; j--)
        if (upperB[j][0] && upperB[j][0] > lst) {
          upperB[i][1] += (upperB[i][0] - 1) * (n - upperB[j][0]) * 2;
          lst = upperB[j][0];
        } else
          break;
      lst = upperB[i][0];
      for (int j = i - 1; j > 0; j--)
        if (upperB[j][0] && upperB[j][0] < lst) {
          upperB[i][1] += (n - upperB[i][0]) * (upperB[j][0] - 1) * 2;
          lst = upperB[j][0];
        } else
          break;
    }
  for (int i = 1; i <= n; i++)
    if (leftB[i][0]) {
      int lst;
      leftB[i][1] += (leftB[i][0] - 1) * (m - leftB[i][0]) * 2 * 2;
      lst = leftB[i][0];
      for (int j = i + 1; j <= n; j++)
        if (leftB[j][0] && leftB[j][0] > lst) {
          leftB[i][1] += (leftB[i][0] - 1) * (m - leftB[j][0]) * 2;
          lst = leftB[j][0];
        } else
          break;
      lst = leftB[i][0];
      for (int j = i + 1; j <= n; j++)
        if (leftB[j][0] && leftB[j][0] < lst) {
          leftB[i][1] += (m - leftB[i][0]) * (leftB[j][0] - 1) * 2;
          lst = leftB[j][0];
        } else
          break;
      lst = leftB[i][0];
      for (int j = i - 1; j > 0; j--)
        if (leftB[j][0] && leftB[j][0] > lst) {
          leftB[i][1] += (leftB[i][0] - 1) * (m - leftB[j][0]) * 2;
          lst = leftB[j][0];
        } else
          break;
      lst = leftB[i][0];
      for (int j = i - 1; j > 0; j--)
        if (leftB[j][0] && leftB[j][0] < lst) {
          leftB[i][1] += (m - leftB[i][0]) * (leftB[j][0] - 1) * 2;
          lst = leftB[j][0];
        } else
          break;
    }
  long long ans = 0;
  for (int i = 1; i <= m; i++) ans += upperB[i][1];
  for (int j = 1; j <= n; j++) ans += leftB[j][1];
  return ans;
}
vector<pair<int, int> > v;
int main() {
  cin >> n >> m;
  long long ans = 0;
  int k = 0;
  ans = dist();
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++)
      if (s[j] == 'X') {
        ans -= dist(i, j) * 2;
        leftB[i + 1][0] = j + 1;
        upperB[j + 1][0] = i + 1;
        v.push_back(make_pair(i, j));
      } else
        k++;
  }
  for (int i = 0; i < v.size(); i++)
    for (int j = 0; j < v.size(); j++)
      ans += abs(v[i].first - v[j].first) + abs(v[i].second - v[j].second);
  ans += calc();
  printf("%.9lf", 1.0 * ans / (1.0 * k * k));
  return 0;
}
