#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
int n, m;
char a[MAXN][MAXN];
int x = MAXN, y;
int kol;
int sum[MAXN][MAXN];
int _sum(int x, int y, int x2, int y2) {
  return (sum[x2][y2] - (x > 0 ? sum[x - 1][y2] : 0) -
          (y > 0 ? sum[x2][y - 1] : 0) +
          (x > 0 && y > 0 ? sum[x - 1][y - 1] : 0));
}
bool ok(int i, int j) { return (i >= 0 && j >= 0 && i < n && j < m); }
bool _try(int q, int qq, int idx = x, int idy = y, int cnt = 0) {
  if (!ok(idx + q - 1, idy + qq - 1)) return 0;
  if (_sum(idx, idy, idx + q - 1, idy + qq - 1) != q * qq) return 0;
  cnt += q * qq;
  if (cnt == kol) return 1;
  if (ok(idx + q, idy + qq - 1) && ok(idx + q - 1, idy + qq)) {
    if (ok(idx + q, idy) && ok(idx, idy + qq) && a[idx + q][idy] == 'X' &&
        a[idx][idy + qq] == 'X')
      return 0;
    if (_sum(idx + 1, idy, idx + q, idy + qq - 1) == q * qq)
      return _try(q, qq, idx + 1, idy, cnt - (q - 1) * qq);
    else if (_sum(idx, idy + 1, idx + q - 1, idy + qq) == q * qq)
      return _try(q, qq, idx, idy + 1, cnt - (qq - 1) * q);
    else
      return 0;
  } else if (ok(idx + q, idy + qq - 1)) {
    return _try(q, qq, idx + 1, idy, cnt - (q - 1) * qq);
  } else if (ok(idx + q - 1, idy + qq)) {
    return _try(q, qq, idx, idy + 1, cnt - (qq - 1) * q);
  } else {
    return 0;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
      if (a[i][j] == 'X' && i < x) {
        x = i;
        y = j;
      }
      if (a[i][j] == 'X') {
        ++kol;
      }
    }
  }
  sum[0][0] = (a[0][0] == 'X');
  for (int i = 1; i < n; ++i) {
    sum[i][0] = sum[i - 1][0] + (a[i][0] == 'X');
  }
  for (int i = 1; i < m; ++i) {
    sum[0][i] = sum[0][i - 1] + (a[0][i] == 'X');
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j < m; ++j) {
      sum[i][j] =
          sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + (a[i][j] == 'X');
    }
  }
  int ans = MAXN * MAXN + 1;
  for (int q = 1; q <= n; ++q) {
    for (int qq = 1; qq <= m; ++qq) {
      if (_try(q, qq)) {
        ans = min(ans, q * qq);
      }
    }
  }
  if (ans == MAXN * MAXN + 1) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
