#include <bits/stdc++.h>
using namespace std;
const int N = 1005, M = N;
int n, m, x = -1, y, a, b, ans = N * N, sum[N][N];
char s[N][N];
inline int calc(int x, int y) {
  return sum[x][y] - sum[x + a][y] - sum[x][y + b] + sum[x + a][y + b];
}
int check(int x, int y) {
  if (calc(x + 1, y) == a * b) return b + check(x + 1, y);
  if (calc(x, y + 1) == a * b) return a + check(x, y + 1);
  return calc(x, y);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
    for (int j = 0; j < m; j++)
      if (x == -1 && s[i][j] == 'X') {
        x = i;
        y = j;
      }
  }
  for (int i = n - 1; i >= 0; i--)
    for (int j = m - 1; j >= 0; j--)
      sum[i][j] =
          (s[i][j] == 'X') + sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1];
  for (b = 0; y + b < m && s[x][y + b] == 'X'; b++)
    ;
  for (a = 1; x + a <= n && s[x + a - 1][y] == 'X'; a++)
    if (check(x, y) == sum[0][0]) {
      ans = min(ans, a * b);
      break;
    }
  for (a = 0; x + a < n && s[x + a][y] == 'X'; a++)
    ;
  for (b = 1; y + b <= m && s[x][y + b - 1] == 'X'; b++)
    if (check(x, y) == sum[0][0]) ans = min(ans, a * b);
  printf("%d\n", ans == N * N ? -1 : ans);
}
