#include <bits/stdc++.h>
using namespace std;
void RI(int& x) {
  x = 0;
  char c = getchar();
  while (!(c >= '0' && c <= '9' || c == '-')) c = getchar();
  bool flag = 1;
  if (c == '-') {
    flag = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (!flag) x = -x;
}
void RII(int& x, int& y) { RI(x), RI(y); }
void RIII(int& x, int& y, int& z) { RI(x), RI(y), RI(z); }
void RC(char& c) {
  c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
}
char RC() {
  char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
const long long mod = 1e9 + 7;
const long long LINF = 1e18;
const int INF = 1e9;
const double EPS = 1e-8;
int n, m;
bool a[1005][1005];
vector<int> up, dn;
int num[1005];
int le, ri;
bool presolve() {
  for (int j = 1; j <= m; j++) {
    int flag = 0;
    for (int i = 1; i <= n; i++) {
      if (!a[i][j] && flag) flag = 2;
      if (a[i][j]) {
        if (flag == 2) {
          return false;
        }
        if (flag == 0) {
          flag++;
        }
      }
    }
    int ed = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i][j]) {
        num[j]++;
        ed = i;
      }
    }
    up.push_back(ed - num[j] + 1);
    dn.push_back(ed);
  }
  le = 1, ri = m;
  while (num[le] == 0 && le <= n) le++;
  while (num[ri] == 0 && ri >= 1) ri--;
  for (int i = le; i <= ri; i++) {
    if (num[i] == 0) return false;
  }
  le--, ri--;
  for (int i = le + 1; i <= ri; i++) {
    if (up[i] < up[i - 1]) return false;
    if (dn[i] < dn[i - 1]) return false;
  }
  return true;
}
int main() {
  RII(n, m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j] = (RC() == 'X');
    }
  }
  if (!presolve()) {
    puts("-1");
    return 0;
  }
  int tl = 1, tr = 1;
  for (int i = le + 1; i <= ri; i++) {
    if (up[i] == up[i - 1]) {
      tl++;
    } else {
      break;
    }
  }
  for (int i = ri - 1; i >= le; i--) {
    if (dn[i] == dn[i + 1]) {
      tr++;
    } else {
      break;
    }
  }
  int ans = INF;
  for (int i = 1; i <= min(tl, tr); i++) {
    if (le + i > ri) {
      ans = min(ans, i);
      continue;
    }
    int tt = dn[le] - up[le] + 1 - (up[le + i] - up[le + i - 1]);
    if (tt < 1) continue;
    bool flag = true;
    for (int j = le + i + 1; j <= ri; j++) {
      if (up[j] - up[j - 1] != dn[j - i] - dn[j - i - 1]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans = min(ans, tt * i);
    }
  }
  if (ans == INF) {
    puts("-1");
  } else {
    printf("%d\n", ans);
  }
}
