#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1111;
const int IT = 20;
int n, m;
bool a[MAXN][MAXN];
int sum[MAXN][MAXN];
int cnt(int x1, int y1, int x2, int y2) {
  return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
}
bool check(int x, int y, int w, int h, int cn) {
  if (x + w - 1 > n || y + h - 1 > m) return false;
  if (cnt(x, y, x + w - 1, y + h - 1) != w * h) {
    return false;
  }
  if (cn == w * h) {
    return true;
  }
  if (x + 1 + w - 1 <= n && y + 1 + h - 1 <= m && a[x + w][y] && a[x][y + h])
    return false;
  if (x + 1 + w - 1 <= n && a[x + w][y + h - 1] &&
      check(x + 1, y, w, h, cn - h))
    return true;
  if (y + 1 + h - 1 <= m && a[x + w - 1][y + h] &&
      check(x, y + 1, w, h, cn - w))
    return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  pair<int, int> mLEFT = make_pair(MAXN, MAXN);
  pair<int, int> mUP = make_pair(MAXN, MAXN);
  pair<int, int> mDOWN = make_pair(-1, -1);
  pair<int, int> mRIGHT = make_pair(-1, -1);
  int sv = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      if (c == 'X') {
        a[i][j] = true;
        sv++;
        if (i < mUP.first) {
          mUP = make_pair(i, j);
        }
        if (j < mLEFT.second) {
          mLEFT = make_pair(i, j);
        }
        if (i >= mDOWN.first) {
          mDOWN = make_pair(i, j);
        }
        if (j >= mRIGHT.second) {
          mRIGHT = make_pair(i, j);
        }
      }
    }
  }
  if (mLEFT.second < mUP.second) {
    cout << -1;
    return 0;
  }
  if (mRIGHT.second > mDOWN.second) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      sum[i][j] =
          -sum[i - 1][j - 1] + sum[i - 1][j] + sum[i][j - 1] + (int)a[i][j];
    }
  int ans = MAXN * MAXN + 5;
  for (int h = 1; h <= m; h++) {
    if (mUP.second + h - 1 > m) break;
    if (cnt(mUP.first, mUP.second, mUP.first, mUP.second + h - 1) < h) break;
    if (h >= ans) break;
    for (int w = 1; w <= n; w++) {
      if (w * h >= ans) break;
      if (cnt(mUP.first, mUP.second, mUP.first + w - 1, mUP.second) < w) break;
      if (check(mUP.first, mUP.second, w, h, sv)) {
        ans = min(w * h, ans);
        break;
      }
    }
  }
  if (ans == MAXN * MAXN + 5) {
    cout << -1;
    return 0;
  }
  cout << ans;
}
