#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10, inf = 1e7;
char a[maxn][maxn];
int s[maxn][maxn];
int sum(int r1, int c1, int r2, int c2) {
  r1--, c1--;
  return s[r2][c2] - s[r2][c1] - s[r1][c2] + s[r1][c1];
}
int okay(int r1, int c1, int r2, int c2) {
  if (sum(r1, c1, r2, c2) != (r2 - r1 + 1) * (c2 - c1 + 1)) return inf;
  if (sum(r1 + 1, c1, r2 + 1, c2) == (r2 - r1 + 1) * (c2 - c1 + 1))
    return (c2 - c1 + 1) + okay(r1 + 1, c1, r2 + 1, c2);
  if (sum(r1, c1 + 1, r2, c2 + 1) == (r2 - r1 + 1) * (c2 - c1 + 1))
    return (r2 - r1 + 1) + okay(r1, c1 + 1, r2, c2 + 1);
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, paint = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j], paint += (a[i][j] == 'X');
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (a[i][j] == 'X');
  int xs = -1, ys = -1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == 'X' && xs == -1) xs = i, ys = j;
  vector<pair<int, int> > cand;
  int r1 = xs, c1 = ys;
  while (c1 + 1 <= m && a[r1][c1 + 1] == 'X') c1++;
  for (int i = 1; i <= n; i++)
    if (a[i][c1] == 'X') cand.push_back(pair<int, int>(i, c1));
  int r2 = xs, c2 = ys;
  while (r2 + 1 <= n && a[r2 + 1][c2] == 'X') r2++;
  for (int i = 1; i <= m; i++)
    if (a[r2][i] == 'X') cand.push_back(pair<int, int>(r2, i));
  int ans = inf;
  for (int rep = 0; rep < cand.size(); rep++) {
    int xf = cand[rep].first, yf = cand[rep].second;
    if (xf >= xs && yf >= ys &&
        okay(xs, ys, xf, yf) == paint - (xf - xs + 1) * (yf - ys + 1))
      ans = min(ans, (xf - xs + 1) * (yf - ys + 1));
  }
  cout << (ans == inf ? -1 : ans) << endl;
  return 0;
}
