#include <bits/stdc++.h>
using namespace std;
char Map[1010][1010];
int X_num;
int x_sta, y_sta;
int x, y;
int n, m;
void Get_Min_xy() {
  x = 1010, y = 1010;
  for (int i = 1; i <= n; ++i) {
    int cnt = 0;
    for (int j = 1; j <= m; ++j) {
      if (Map[i][j] == 'X') {
        cnt++;
      } else {
        if (cnt) y = min(cnt, y);
        cnt = 0;
      }
    }
    if (cnt) {
      y = min(cnt, y);
    }
  }
  for (int i = 1; i <= m; ++i) {
    int cnt = 0;
    for (int j = 1; j <= n; ++j) {
      if (Map[j][i] == 'X') {
        cnt++;
      } else {
        if (cnt) x = min(cnt, x);
        cnt = 0;
      }
    }
    if (cnt) {
      x = min(cnt, x);
    }
  }
}
bool judge(int x, int y) {
  int nowx = x_sta, nowy = y_sta;
  if (nowx + x - 1 > n || nowy + y - 1 > m) return false;
  for (int i = 0; i < x; i++)
    for (int j = 0; j < y; j++)
      if (Map[i + nowx][j + nowy] != 'X') return false;
  int cnt = x * y;
  while (1) {
    if (nowx + x <= n && Map[nowx + x][nowy] == 'X') {
      nowx++;
      for (int i = 0; i < y; i++)
        if (Map[nowx + x - 1][i + nowy] != 'X') return false;
      cnt += y;
    } else if (nowy + y <= m && Map[nowx][nowy + y] == 'X') {
      nowy++;
      for (int i = 0; i < x; i++)
        if (Map[i + nowx][nowy + y - 1] != 'X') return false;
      cnt += x;
    } else
      break;
  }
  return cnt == X_num;
}
int work() {
  if (x <= 0 || y <= 0) return -1;
  int area = 1010 * 1010;
  for (int i = 1; i <= x; i++) {
    if (judge(i, y)) {
      area = i * y;
      break;
    }
  }
  for (int j = 1; j <= y && x * j < area; j++) {
    if (judge(x, j)) {
      area = x * j;
      break;
    }
  }
  if (area > n * m) return -1;
  return area;
}
int main() {
  scanf("%d %d", &n, &m);
  getchar();
  X_num = 0;
  bool flag = 1;
  for (int i = 1; i <= n; ++i) {
    gets(Map[i] + 1);
    for (int j = 1; j <= m; ++j) {
      X_num += (Map[i][j] == 'X');
      if (flag && Map[i][j] == 'X') {
        flag = 0;
        x_sta = i;
        y_sta = j;
      }
    }
  }
  Get_Min_xy();
  printf("%d\n", work());
  return 0;
}
