#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int N = 1e3 + 11;
int n, m;
char s[N][N];
int x, y;
int hen, shu;
void gt() {
  int i, j, r;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == 'X') {
        x = i;
        y = j;
        for (r = j; r < m; r++) {
          if (s[i][r] == 'X')
            hen = r - j + 1;
          else
            break;
        }
        for (r = i; r < n; r++) {
          if (s[r][j] == 'X')
            shu = r - i + 1;
          else
            break;
        }
        return;
      }
    }
  }
}
int tx, ty;
int ans;
int tot;
int cc[N][N];
int gtsum(int x1, int y1, int x2, int y2) {
  int res = cc[x2][y2];
  if (y1) res -= cc[x2][y1 - 1];
  if (x1) res -= cc[x1 - 1][y2];
  if (x1 && y1) res += cc[x1 - 1][y1 - 1];
  return res;
}
void test() {
  int x2 = x + tx - 1, y2 = y + ty - 1;
  int now = tx * ty;
  bool f = 1;
  int x1 = x;
  int y1 = y;
  while (1) {
    if (f)
      f = 0;
    else
      break;
    if (gtsum(x1, y2 + 1, x2, y2 + 1) == tx) {
      now += tx;
      y1++;
      y2++;
      f = 1;
    }
    if (gtsum(x2 + 1, y1, x2 + 1, y2) == ty) {
      now += ty;
      x1++;
      x2++;
      f = 1;
    }
  }
  if (now == tot) {
    ans = min(ans, tx * ty);
  }
}
int main() {
  cin >> n >> m;
  int i, j;
  tot = 0;
  for (i = 0; i < n; i++) scanf("%s", s[i]);
  ans = inf;
  gt();
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      if (i) cc[i][j] += cc[i - 1][j];
      if (j) cc[i][j] += cc[i][j - 1];
      if (i && j) cc[i][j] -= cc[i - 1][j - 1];
      if (s[i][j] == 'X') {
        cc[i][j]++;
        tot++;
      }
    }
  ty = hen;
  for (i = 1; i <= shu; i++) {
    tx = i;
    test();
  }
  tx = shu;
  for (i = 1; i <= hen; i++) {
    ty = i;
    test();
  }
  if (ans == inf)
    puts("-1");
  else
    cout << ans;
  return 0;
}
