#include <bits/stdc++.h>
int n, m, tx, ty;
char c[1010][1010], cc[2][1010][1010];
bool check(int d) {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (cc[d][i][j] == '.') continue;
      return false;
    }
  }
  return true;
}
bool run(int d, int sy, int sx) {
  int co[4][2];
  co[0][0] = ty;
  co[0][1] = tx;
  co[1][0] = ty + sy - 1;
  co[1][1] = tx;
  co[2][0] = ty;
  co[2][1] = tx + sx - 1;
  co[3][0] = ty + sy - 1;
  co[3][1] = tx + sx - 1;
  for (int i = co[0][0]; i <= co[3][0]; i++) {
    for (int j = co[0][1]; j <= co[3][1]; j++) {
      if (cc[d][i][j] == '.') return false;
      cc[d][i][j] = '.';
    }
  }
  while (1) {
    bool left = 0, down = 0;
    if (cc[d][co[1][0] + 1][co[1][1]] == 'X') down = 1;
    if (cc[d][co[2][0]][co[2][1] + 1] == 'X') left = 1;
    if (down && left) return false;
    if (!down && !left) return true;
    if (down) {
      if (co[3][0] == n) return true;
      for (int i = 0; i < 4; i++) co[i][0]++;
      for (int i = co[1][1]; i <= co[3][1]; i++) {
        if (cc[d][co[1][0]][i] == '.') return false;
        cc[d][co[1][0]][i] = '.';
      }
    }
    if (left) {
      if (co[3][1] == m) return true;
      for (int i = 0; i < 4; i++) co[i][1]++;
      for (int i = co[2][0]; i <= co[3][0]; i++) {
        if (cc[d][i][co[2][1]] == '.') return false;
        cc[d][i][co[2][1]] = '.';
      }
    }
  }
}
int func0() {
  int i, j, k, sx, sy;
  for (i = tx; i <= m && cc[0][ty][i] == 'X'; i++)
    ;
  for (j = ty; j <= n && cc[0][j][tx] == 'X' && cc[0][j][i] == '.'; j++) {
    for (k = tx; k < i; k++) {
      if (cc[0][j][k] == '.') return -1;
    }
  }
  if (cc[0][j][tx] == '.') {
    for (int ii = ty; ii < j; ii++) {
      for (int jj = tx; jj < i; jj++) {
        cc[0][ii][jj] = '.';
      }
    }
    if (!check(0)) return -1;
    return i - tx;
  }
  for (k = j; j <= n && cc[0][j][tx] == 'X'; j++)
    ;
  sy = j - k;
  sx = i - tx;
  if (!run(0, sy, sx)) return -1;
  if (!check(0)) return -1;
  return sy * sx;
}
int func1() {
  int i, j, k, sx, sy;
  for (i = ty; i <= n && cc[1][i][tx] == 'X'; i++)
    ;
  for (j = tx; j <= m && cc[1][ty][j] == 'X' && cc[1][i][j] == '.'; j++) {
    for (k = ty; k < i; k++) {
      if (cc[1][k][j] == '.') return -1;
    }
  }
  if (cc[1][ty][j] == '.') {
    for (int ii = ty; ii < i; ii++) {
      for (int jj = tx; jj < j; jj++) {
        cc[1][ii][jj] = '.';
      }
    }
    if (!check(1)) return -1;
    return i - ty;
  }
  for (k = j; j <= m && cc[1][ty][j] == 'X'; j++)
    ;
  sy = i - ty;
  sx = j - k;
  if (!run(1, sy, sx)) return -1;
  if (!check(1)) return -1;
  return sy * sx;
}
int main() {
  int i, j, k;
  memset(cc, '.', sizeof(cc));
  bool ch = 0;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%s", c[i]);
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      cc[0][i][j] = c[i - 1][j - 1];
      cc[1][i][j] = c[i - 1][j - 1];
    }
  }
  tx = -1;
  ty = -1;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (cc[0][i][j] == 'X') {
        tx = j;
        ty = i;
        ch = 1;
        break;
      }
    }
    if (ch == 1) break;
  }
  if (tx == -1) {
    printf("-1");
    return 0;
  }
  i = func0();
  j = func1();
  if ((i > j && j != -1) || i == -1) i = j;
  printf("%d", i);
  return 0;
}
