#include <bits/stdc++.h>
using namespace std;
string s[1000];
int a[1000], b[1000];
char S[1000][1000];
int main() {
  int n, m;
  cin >> n >> m;
  for (int(i) = (0); i < (n); ++(i)) cin >> s[i];
  for (int(i) = (0); i < (n); ++(i)) {
    int p = 0;
    for (int(j) = (0); j < (m); ++(j)) {
      if (s[i][j] == '.')
        p = 0;
      else {
        if (a[i] == 0 || p) {
          a[i]++;
          p = 1;
        } else {
          cout << -1;
          return 0;
        }
      }
    }
  }
  for (int(i) = (0); i < (m); ++(i)) {
    int p = 0;
    for (int(j) = (0); j < (n); ++(j)) {
      if (s[j][i] == '.')
        p = 0;
      else {
        if (b[i] == 0 || p) {
          b[i]++;
          p = 1;
        } else {
          cout << -1;
          return 0;
        }
      }
    }
  }
  int xx = 0, yy = 0, b1 = 1, b2 = 1, ans1 = 10000000, ans2 = 10000000;
  while (!a[xx]) xx++;
  while (!b[yy]) yy++;
  int Axx = a[xx], Bxx = b[yy];
  if (s[xx][yy] == '.') {
    cout << -1;
    return 0;
  }
  for (int(i) = (0); i < (n); ++(i))
    if (a[i] && a[i] < a[xx]) b1 = 0;
  for (int(i) = (0); i < (m); ++(i))
    if (b[i] && b[i] < b[yy]) b2 = 0;
  if (b1) {
    int l[1000], r[1000], ll[1000], rr[1000];
    int P1 = xx, P2 = yy + Axx - 1;
    l[P1] = r[P1] = P2;
    while (true) {
      int k = 0;
      if (P2 + 1 < m && s[P1][P2 + 1] == 'X') {
        k = 1;
        P2++;
        r[P1] = P2;
      } else if (P1 + 1 < n && s[P1 + 1][P2] == 'X') {
        k = 1;
        P1++;
        l[P1] = r[P1] = P2;
      }
      if (!k) break;
    }
    int Q1 = xx, Q2 = yy;
    ll[Q1] = rr[Q1] = Q2;
    while (true) {
      int k = 0;
      if (Q1 + 1 < n && s[Q1 + 1][Q2] == 'X') {
        k = 1;
        Q1++;
        ll[Q1] = rr[Q1] = Q2;
      } else if (Q2 + 1 < m && s[Q1][Q2 + 1] == 'X') {
        k = 1;
        Q2++;
        rr[Q1] = Q2;
      }
      if (!k) break;
    }
    int len_m = 1, len_M = 1;
    while (len_M <= P1 && r[P1 - len_M] == P2) len_M++;
    while (len_m != len_M) {
      int QWE = (len_m + len_M) / 2, f = 0;
      for (int(i) = (xx); i < (P1 + 2 - QWE); ++(i))
        if (ll[i + QWE - 1] < l[i] - Axx + 1) f = 1;
      if (f)
        len_m = QWE + 1;
      else
        len_M = QWE;
    }
    int ok = 1;
    for (int(i) = (0); i < (len_M); ++(i))
      if (ll[xx + i] != l[xx] - Axx + 1) ok = 0;
    for (int(i) = (xx); i < (P1 + 2 - len_M); ++(i))
      if (ll[i + len_M - 1] != l[i] - Axx + 1) ok = 0;
    for (int(i) = (P1 + 1); i < (n); ++(i))
      if (a[i]) ok = 0;
    if (ok) ans1 = Axx * len_M;
  }
  for (int(i) = (0); i < (n); ++(i))
    for (int(j) = (0); j < (m); ++(j)) S[j][i] = s[i][j];
  swap(n, m);
  Axx = Bxx;
  swap(xx, yy);
  if (b2) {
    int l[1000], r[1000], ll[1000], rr[1000];
    int P1 = xx, P2 = yy + Axx - 1;
    l[P1] = r[P1] = P2;
    while (true) {
      int k = 0;
      if (P2 + 1 < m && S[P1][P2 + 1] == 'X') {
        k = 1;
        P2++;
        r[P1] = P2;
      } else if (P1 + 1 < n && S[P1 + 1][P2] == 'X') {
        k = 1;
        P1++;
        l[P1] = r[P1] = P2;
      }
      if (!k) break;
    }
    int Q1 = xx, Q2 = yy;
    ll[Q1] = rr[Q1] = Q2;
    while (true) {
      int k = 0;
      if (Q1 + 1 < n && S[Q1 + 1][Q2] == 'X') {
        k = 1;
        Q1++;
        ll[Q1] = rr[Q1] = Q2;
      } else if (Q2 + 1 < m && S[Q1][Q2 + 1] == 'X') {
        k = 1;
        Q2++;
        rr[Q1] = Q2;
      }
      if (!k) break;
    }
    int len_m = 1, len_M = 1;
    while (len_M <= P1 && r[P1 - len_M] == P2) len_M++;
    while (len_m != len_M) {
      int QWE = (len_m + len_M) / 2, f = 0;
      for (int(i) = (xx); i < (P1 + 2 - QWE); ++(i))
        if (ll[i + QWE - 1] < l[i] - Axx + 1) f = 1;
      if (f)
        len_m = QWE + 1;
      else
        len_M = QWE;
    }
    int ok = 1;
    for (int(i) = (0); i < (len_M); ++(i))
      if (ll[xx + i] != l[xx] - Axx + 1) ok = 0;
    for (int(i) = (xx); i < (P1 + 2 - len_M); ++(i))
      if (ll[i + len_M - 1] != l[i] - Axx + 1) ok = 0;
    for (int(i) = (P1 + 1); i < (n); ++(i))
      if (b[i]) ok = 0;
    if (ok) ans2 = Axx * len_M;
  }
  if (min(ans1, ans2) > n * m) {
    cout << -1;
    return 0;
  } else
    cout << min(ans1, ans2);
}
