#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 10;
char str[MAXN][MAXN];
int n, m, l[MAXN], r[MAXN], u[MAXN], d[MAXN], a[MAXN][MAXN], b[MAXN][MAXN],
    Tohka;
int px, py;
void fail() { puts("-1"), exit(0); }
int idx;
void check(int first, int second) {
  for (int cx = px, cy = py;;) {
    if (!(cy >= l[cx] && cy + second - 1 <= r[cx] && cx >= u[cy] &&
          cx + first - 1 <= d[cy]))
      return;
    if (cy + second - 1 == r[cx] && cx + first - 1 == d[cy]) {
      for (int i = cx; i <= cx + first - 1; ++i)
        if (r[i] != r[cx]) return;
      for (int i = cy; i <= cy + second - 1; ++i)
        if (d[i] != d[cy]) return;
      for (int i = cx + first; i <= n; ++i)
        if (l[i]) return;
      break;
    }
    if (cy + second - 1 == r[cx])
      ++cx;
    else if (cx + first - 1 == d[cy])
      ++cy;
    else
      return;
  }
  Tohka = min(Tohka, first * second);
}
int main() {
  bool flag = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%s", str[i] + 1);
  for (int i = 1; i <= n; ++i) {
    int cnt = 0;
    l[i] = m, r[i] = 1;
    for (int j = 1; j <= m; ++j)
      if (str[i][j] == 'X') {
        flag = 1;
        l[i] = min(l[i], j);
        r[i] = max(r[i], j);
        if (str[i][j - 1] != 'X') ++cnt;
      }
    if (cnt > 1) fail();
    if (!cnt) l[i] = r[i] = 0;
  }
  if (!flag) fail();
  for (int i = 1; i <= m; ++i) {
    int cnt = 0;
    u[i] = n, d[i] = 1;
    for (int j = 1; j <= n; ++j)
      if (str[j][i] == 'X') {
        u[i] = min(u[i], j);
        d[i] = max(d[i], j);
        if (str[j - 1][i] != 'X') ++cnt;
      }
    if (cnt > 1) fail();
    if (!cnt) u[i] = d[i] = 0;
  }
  px = 0, py = 0;
  for (int i = 1; i <= n; ++i) {
    if (l[i] && l[i - 1]) {
      if (!(l[i - 1] <= l[i] && l[i] <= r[i - 1] && r[i - 1] <= r[i])) fail();
    }
    if (l[i])
      if (!px) px = i, py = l[i];
  }
  for (int i = 1; i <= m; ++i)
    if (u[i] && u[i - 1])
      if (!(u[i - 1] <= u[i] && u[i] <= d[i - 1] && d[i - 1] <= d[i])) fail();
  Tohka = n * m + 1;
  for (int i = 1; i <= r[px] - l[px] + 1; ++i) check(d[py] - u[py] + 1, i);
  for (int i = 1; i <= d[py] - u[py] + 1; ++i) check(i, r[px] - l[px] + 1);
  if (Tohka > n * m) fail();
  cout << Tohka << endl;
  fclose(stdin);
  fclose(stdout);
  return 0;
}
