#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double EPS = 0.000000001;
const double PI = 3.141592653589793;
const long long LLINF = 99999999999999999LL;
const int MAX_N = 1005;
const int MOD = 1000000007;
int N, M, K;
int A[MAX_N][MAX_N], l[MAX_N], r[MAX_N], u[MAX_N], d[MAX_N];
bool B[MAX_N][MAX_N];
void Fill(int x, int y) {
  queue<pair<int, int> > Q;
  Q.push(make_pair(x, y));
  while (!Q.empty()) {
    int x = Q.front().first, y = Q.front().second;
    Q.pop();
    for (int i = -1; i <= 1; ++i)
      for (int j = -1; j <= 1; ++j)
        if (!i || !j) {
          int x1 = x + i, y1 = y + j;
          if (x1 >= 1 && x1 <= N && y1 >= 1 && y1 <= M && A[x1][y1] &&
              !B[x1][y1]) {
            B[x1][y1] = 1;
            Q.push(make_pair(x1, y1));
          }
        }
  }
}
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= M; ++j) {
      char c;
      cin >> c;
      if (c == 'X') A[i][j] = 1;
    }
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= M; ++j)
      if (A[i][j]) {
        if (!l[i]) l[i] = j;
        r[i] = j;
        if (!u[j]) u[j] = i;
        d[j] = i;
      }
  bool ok = 1;
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= M; ++j)
      if (A[i][j]) {
        Fill(i, j);
        break;
      }
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= M; ++j)
      if (A[i][j] && !B[i][j]) ok = 0;
  for (int i = 1; i <= N; ++i)
    if (l[i])
      for (int j = l[i]; j <= r[i]; ++j)
        if (!A[i][j]) ok = 0;
  for (int j = 1; j <= M; ++j)
    if (u[j])
      for (int i = u[j]; i <= d[j]; ++i)
        if (!A[i][j]) ok = 0;
  for (int i = 1; i <= N; ++i) {
    if (l[i] && l[i] < l[i - 1]) ok = 0;
    if (r[i] && r[i] < r[i - 1]) ok = 0;
  }
  for (int j = 1; j <= M; ++j) {
    if (u[j] && u[j] < u[j - 1]) ok = 0;
    if (d[j] && d[j] < d[j - 1]) ok = 0;
  }
  if (!ok) {
    cout << "-1";
    return 0;
  }
  int L = 0;
  for (int i = 1; i <= N; ++i)
    if (l[i]) L = i;
  int ans = MAX_N * MAX_N;
  for (int x = 1; x <= N; ++x)
    for (int y = 1; y <= M; ++y)
      if (A[x][y]) {
        for (int h = d[y] - u[y] + 1, w = 1; w <= r[x] - l[x] + 1; ++w) {
          int b = r[x];
          bool ok = 1;
          for (int i = x + 1; i + h - 1 <= L; ++i)
            if (l[i + h - 1] != b - w + 1) {
              ok = 0;
              break;
            } else
              b = r[i];
          for (int i = L - h + 2; i <= L; ++i)
            if (r[i] != b) ok = 0;
          if (ok) ans = min(ans, h * w);
        }
        for (int w = r[x] - l[x] + 1, h = 1; h <= d[y] - u[y] + 1; ++h) {
          int b = r[x];
          bool ok = 1;
          for (int i = x + 1; i + h - 1 <= L; ++i)
            if (l[i + h - 1] != b - w + 1) {
              ok = 0;
              break;
            } else
              b = r[i];
          for (int i = L - h + 2; i <= L; ++i)
            if (r[i] != b) ok = 0;
          if (ok) ans = min(ans, h * w);
        }
        x = N;
        y = M;
      }
  if (ans != MAX_N * MAX_N)
    cout << ans;
  else
    cout << "-1";
  return 0;
}
