#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
  if (a < b) a = b;
}
int N, M;
bitset<1013> grid[1013];
int dn[1013][1013], rt[1013][1013];
int upd[1013][1013];
int x = -1, y = -1;
int ans = 998244353;
void check(int sx, int sy) {
  for (auto i = (0); i < (N + 1); i++) {
    for (auto j = (0); j < (M + 1); j++) {
      upd[i][j] = 0;
    }
  }
  int cx = x, cy = y;
  while (true) {
    upd[cx][cy]++;
    upd[cx + sx][cy]--;
    upd[cx][cy + sy]--;
    upd[cx + sx][cy + sy]++;
    if (grid[cx + sx][cy]) {
      cx++;
      continue;
    }
    if (grid[cx][cy + sy]) {
      cy++;
      continue;
    }
    break;
  }
  for (auto i = (0); i < (N); i++) {
    for (auto j = (0); j < (M); j++) {
      if (i) upd[i][j] += upd[i - 1][j];
      if (j) upd[i][j] += upd[i][j - 1];
      if (i && j) upd[i][j] -= upd[i - 1][j - 1];
      if (upd[i][j] && !grid[i][j]) return;
      if (!upd[i][j] && grid[i][j]) return;
    }
  }
  ckmin(ans, sx * sy);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M;
  for (auto i = (0); i < (N); i++) {
    string temps;
    cin >> temps;
    for (auto j = (0); j < (M); j++) {
      grid[i][j] = (temps[j] == 'X');
    }
  }
  for (auto i = (N)-1; i >= (0); i--) {
    for (auto j = (M)-1; j >= (0); j--) {
      if (grid[i][j]) {
        x = i;
        y = j;
      }
    }
  }
  for (auto i = (0); i < (N); i++) {
    for (auto j = (0); j < (y); j++) {
      if (grid[i][j]) {
        cout << "-1\n";
        return 0;
      }
    }
  }
  for (auto i = (0); i < (N); i++) {
    for (auto j = (M)-1; j >= (0); j--) {
      rt[i][j] = (grid[i][j] ? 1 + rt[i][j + 1] : 0);
    }
  }
  for (auto i = (0); i < (M); i++) {
    for (auto j = (N)-1; j >= (0); j--) {
      dn[j][i] = (grid[j][i] ? 1 + dn[j + 1][i] : 0);
    }
  }
  int dy = rt[x][y], dx = dn[x][y];
  for (auto i = (x); i < (x + dx); i++) {
    for (auto j = (y); j < (y + dy); j++) {
      if (!grid[i][j]) {
        cout << "-1\n";
        return 0;
      }
    }
  }
  check(dx, dy);
  check(dx, 1);
  check(1, dy);
  for (auto i = (0); i < (dy); i++) {
    if (grid[x + dx][y + i]) {
      check(dx, dy - i);
      break;
    }
  }
  for (auto i = (0); i < (dx); i++) {
    if (grid[x + i][y + dy]) {
      check(dx - i, dy);
      break;
    }
  }
  if (ans == 998244353) {
    cout << "-1\n";
    return 0;
  }
  cout << ans << '\n';
  return 0;
}
