#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return f ? x : -x;
}
const long long N = 1005;
long long n, m, sum[N][N], minx, miny, ans = INT_MAX;
char ch[N][N];
long long get(long long x1, long long y1, long long x2, long long y2) {
  return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
}
bool check(long long x, long long y, long long a, long long b) {
  if (x + a - 1 > n || y + b - 1 > m) return 0;
  if (get(x, y, x + a - 1, y + b - 1) != a * b) return 0;
  if (get(x + a, y, n, y) > 0 && get(x, y + b, x, m) > 0) return 0;
  if (get(x + a, y, n, m) == 0 && get(x, y + b, n, m) == 0) return 1;
  if (get(x + a, y, n, y) > 0) return check(x + 1, y, a, b);
  return check(x, y + 1, a, b);
}
signed main() {
  minx = n = read(), miny = m = read();
  for (long long i = 1; i <= n; i++) scanf("%s", ch[i] + 1);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      sum[i][j] =
          sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + (ch[i][j] == 'X');
      if (ch[i][j] == 'X') {
        minx = min(minx, i);
        miny = min(miny, j);
      }
    }
  }
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++)
      if (check(minx, miny, i, j)) ans = min(ans, i * j);
  printf("%lld", ans == INT_MAX ? -1 : ans);
  return 0;
}
