#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3;
int sum[MAXN + 2 + 10][MAXN + 2 + 10];
int n, m, sx = -1, sy = -1, tot = 0;
bool canGo(int cx, int cy, int w, int h) {
  return (cx + w - 1 <= m && cy + h - 1 <= n &&
          sum[cy + h - 1][cx + w - 1] - sum[cy + h - 1][cx - 1] -
                  sum[cy - 1][cx + w - 1] + sum[cy - 1][cx - 1] ==
              w * h);
}
bool solve(int w, int h) {
  int cx = sx, cy = sy, ctot = w * h;
  bool down, right;
  while (ctot < tot) {
    down = canGo(cx, cy + 1, w, h);
    right = canGo(cx + 1, cy, w, h);
    if (down && right) {
      return false;
    }
    if (!down && !right) {
      return false;
    }
    if (down) {
      ctot += w;
      cy += 1;
    } else if (right) {
      ctot += h;
      cx += 1;
    }
  }
  return true;
}
int main() {
  std::ios::sync_with_stdio(false);
  int maxx = 0, maxy = 0, res = 1e9;
  bool biggermaxx = false, biggermaxy = false;
  char c;
  cin >> n >> m;
  for (int i = 0; i <= n; ++i) {
    sum[i][0] = 0;
  }
  for (int i = 0; i <= m; ++i) {
    sum[0][i] = 0;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> c;
      sum[i][j] =
          sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + (c == 'X');
      if (c == 'X') {
        tot += 1;
      }
      if (c == 'X' && sx == -1) {
        sy = i;
        sx = j;
        biggermaxx = true;
        biggermaxy = true;
      }
      if (biggermaxx && i == sy) {
        if (c == 'X') {
          maxx += 1;
        } else {
          biggermaxx = false;
        }
      }
      if (biggermaxy && j == sx) {
        if (c == 'X') {
          maxy += 1;
        } else {
          biggermaxy = false;
        }
      }
    }
  }
  for (int i = 1; i <= maxx; ++i) {
    if (solve(i, maxy)) {
      res = min(res, i * maxy);
    }
  }
  for (int i = 1; i <= maxy; ++i) {
    if (solve(maxx, i)) {
      res = min(res, maxx * i);
    }
  }
  if (res == 1e9) {
    cout << -1 << "\n";
  } else {
    cout << res << "\n";
  }
  return 0;
}
