#include <bits/stdc++.h>
using namespace std;
int n, m;
int sum[1010][1010];
char mp[1010][1010];
int getsum(int x1, int y1, int x2, int y2) {
  return sum[x1][y1] - sum[x2 + 1][y1] - sum[x1][y2 + 1] + sum[x2 + 1][y2 + 1];
}
bool check(int a, int b, int x, int y) {
  while (1) {
    if (x + a - 1 > n || y + b - 1 > m) return 0;
    if (getsum(x, y, x + a - 1, y + b - 1) != a * b) return 0;
    if (getsum(x + a, y, n, y) > 0 && getsum(x, y + b, x, m) > 0) return 0;
    if (sum[x + a][y] == 0 && sum[x][y + b] == 0) break;
    if (getsum(x + a, y, n, y) > 0) {
      x++;
      if (getsum(x + a - 1, y, x + a - 1, y + b - 1) > 0 &&
          getsum(x + a - 1, y, x + a - 1, y + b - 1) != b)
        return 0;
    } else {
      y++;
      if (getsum(x, y + b - 1, x + a - 1, y + b - 1) > 0 &&
          getsum(x, y + b - 1, x + a - 1, y + b - 1) != a)
        return 0;
    }
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", mp[i] + 1);
  memset(sum, 0, sizeof(sum));
  int x0, y0;
  x0 = y0 = 10000;
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--) {
      sum[i][j] =
          sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1] + (mp[i][j] == 'X');
      if (mp[i][j] == 'X') {
        x0 = min(x0, i);
        y0 = min(y0, j);
      }
    }
  int ans = n * m + 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (i * j >= ans) continue;
      if (check(i, j, x0, y0)) ans = i * j;
    }
  if (ans > n * m)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
