#include <bits/stdc++.h>
int table[1100][1100];
int sum[1100][1100];
char buf[1100];
int area;
int row, col;
int row_pos, col_pos;
int m, n;
int start_row, start_col;
int max_row, max_col;
int cnt, tot;
int dfs(int row_pos, int col_pos) {
  int col_move;
  int row_move;
  int i;
  if (0 == ((row_pos + row <= m) && (col_pos + col <= n) &&
            (sum[row_pos + row][col_pos + col] - sum[row_pos + row][col_pos] -
                 sum[row_pos][col_pos + col] + sum[row_pos][col_pos] ==
             (row) * (col)))) {
    return -1;
  }
  cnt = row * col;
  while (1) {
    if (tot == cnt) {
      return 0;
    }
    col_move = 0;
    for (i = 1;
         ((row_pos + row <= m) && (col_pos + i + col <= n) &&
          (sum[row_pos + row][col_pos + i + col] - sum[row_pos + row][col_pos] -
               sum[row_pos][col_pos + i + col] + sum[row_pos][col_pos] ==
           (row) * (i + col)));
         i++) {
      col_move++;
    }
    row_move = 0;
    for (i = 1; ((row_pos + i + row <= m) && (col_pos + col <= n) &&
                 (sum[row_pos + i + row][col_pos + col] -
                      sum[row_pos + i + row][col_pos] -
                      sum[row_pos][col_pos + col] + sum[row_pos][col_pos] ==
                  (i + row) * (col)));
         i++) {
      row_move++;
    }
    if (!col_move && !row_move) return -1;
    if (col_move && row_move) return -1;
    if (col_move) {
      col_pos += col_move;
      cnt += row * col_move;
    } else {
      row_pos += row_move;
      cnt += col * row_move;
    }
  }
}
int main() {
  int start_find = 0;
  int i, j;
  tot = 0;
  scanf("%d%d", &m, &n);
  getchar();
  for (i = 0; i < m; i++) {
    gets(buf);
    for (j = 0; j < n; j++) {
      if (buf[j] == 'X') {
        table[i][j] = 1;
        if (start_find == 0) {
          start_find = 1;
          start_row = i;
          start_col = j;
        }
        tot++;
      } else {
        table[i][j] = 0;
      }
      sum[i + 1][j + 1] =
          sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + (table[i][j] ? 1 : 0);
    }
  }
  for (max_row = 0;
       (start_row + max_row <= m) && table[start_row + max_row][start_col];
       max_row++)
    ;
  for (max_col = 0;
       (start_col + max_col <= n) && table[start_row][start_col + max_col];
       max_col++)
    ;
  area = 0x7fffffff;
  for (col = max_col, row = 1; row <= max_row; row++)
    if (0 == dfs(start_row, start_col))
      area = ((area) < (row * col) ? (area) : (row * col));
  for (row = max_row, col = 1; col <= max_col; col++)
    if (0 == dfs(start_row, start_col))
      area = ((area) < (row * col) ? (area) : (row * col));
  if (area == 0x7fffffff)
    printf("-1\n");
  else
    printf("%d\n", area);
  return 0;
}
