#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9;
char board[1005][1005];
int n, m, cx, cy = oo, s[1005][1005];
int sum(int c1x, int c1y, int c2x, int c2y) {
  return s[c2x][c2y] - s[c1x - 1][c2y] - s[c2x][c1y - 1] + s[c1x - 1][c1y - 1];
}
bool check(int ix, int iy, int x, int y) {
  if (ix + x - 1 > n || iy + y - 1 > m) return 0;
  if (sum(ix, iy, ix + x - 1, iy + y - 1) != x * y) return 0;
  if (sum(ix, iy, n, m) == x * y) return 1;
  if (sum(ix + x, iy, n, iy) == 0 && iy < m && check(ix, iy + 1, x, y) == 1)
    return 1;
  if (sum(ix, iy + y, ix, m) == 0 && ix < n && check(ix + 1, iy, x, y) == 1)
    return 1;
  return 0;
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> board[i];
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
      if (board[i - 1][j - 1] == 'X') {
        s[i][j]++;
        if (j < cy) {
          cy = j;
          cx = i;
        }
      }
    }
  int ans = oo;
  if (cx != 0 && sum(1, 1, cx - 1, m) == 0 && sum(1, 1, n, cy - 1) == 0) {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        if (check(cx, cy, i, j) == 1) {
          ans = min(ans, i * j);
        }
      }
  }
  if (ans != oo)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
