#include <bits/stdc++.h>
using namespace std;
char mp[1005][1005];
int n, m;
inline bool check(int row, int l, int r) {
  int cnt = 0;
  for (int i = 0; i < m; ++i)
    if (mp[row][i] == 'X') ++cnt;
  if (cnt != r - l + 1) return 0;
  for (int i = l; i <= r; ++i)
    if (mp[row][i] == 'X') --cnt;
  return !cnt;
}
struct Rec {
  int x1, y1, x2, y2;
  inline Rec() {}
  inline Rec(int _x1, int _y1, int _x2, int _y2) {
    x1 = _x1;
    y1 = _y1;
    x2 = _x2;
    y2 = _y2;
  }
};
vector<Rec> rec;
inline bool ok(int lx, int ly) {
  if (lx <= 0 || ly <= 0) return 0;
  int cnt = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (mp[i][j] == 'X') ++cnt;
  int x1 = rec[0].x1, y1 = rec[0].y1;
  cnt -= lx * ly;
  while (1) {
    int x2 = x1 + lx - 1, y2 = y1 + ly - 1;
    bool r = 0, d = 0;
    if (y2 + 1 < m && mp[x1][y2 + 1] == 'X') r = 1;
    if (x2 + 1 < n && mp[x2 + 1][y1] == 'X') d = 1;
    if (d && r) return 0;
    if (!d && !r) break;
    if (d)
      ++x1, cnt -= ly;
    else
      ++y1, cnt -= lx;
  }
  return cnt == 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", mp[i]);
  for (int j, i = 0; i < n;) {
    int l = -1, r;
    for (j = 0; j < m; ++j)
      if (mp[i][j] == 'X') {
        l = j;
        break;
      }
    if (l == -1) {
      ++i;
      continue;
    }
    for (j = l + 1; j < m; ++j)
      if (mp[i][j] == '.') break;
    r = j - 1;
    for (j = r + 1; j < m; ++j)
      if (mp[i][j] == 'X') return puts("-1");
    for (j = i + 1; j < n; ++j)
      if (!check(j, l, r)) break;
    int down = j - 1;
    rec.push_back(Rec(i, l, down, r));
    i = j;
  }
  int sz = rec.size();
  if (sz == 1) {
    printf("%d\n", min(rec[0].x2 - rec[0].x1 + 1, rec[0].y2 - rec[0].y1 + 1));
    return 0;
  }
  for (int i = 1; i < sz; ++i) {
    if (rec[i].x1 != rec[i - 1].x2 + 1) return puts("-1");
    if (rec[i].y1 < rec[i - 1].y1) return puts("-1");
    if (rec[i].y2 < rec[i - 1].y2) return puts("-1");
    if (rec[i].y1 > rec[i - 1].y2) return puts("-1");
  }
  int x, y, ans = 0x3f3f3f3f;
  if (rec[0].y1 == rec[1].y1) {
    y = rec[0].y2 - rec[0].y1 + 1;
    x = 0;
    int i;
    for (i = 1; i < sz; ++i) {
      if (rec[i].y1 == rec[0].y1)
        x += rec[i].x2 - rec[i].x1 + 1;
      else
        break;
    }
    if (ok(x, y)) ans = min(ans, x * y);
    if (i < sz) {
      x = 0;
      for (int j = 0; j < sz; ++j)
        if (rec[j].y1 == rec[0].y1) x += rec[j].x2 - rec[j].x1 + 1;
      y = rec[0].y2 - rec[i].y1 + 1;
      if (ok(x, y)) ans = min(ans, x * y);
    }
  } else {
    x = rec[0].x2 - rec[0].x1 + 1, y = rec[0].y2 - rec[1].y1 + 1;
    if (ok(x, y)) ans = min(ans, x * y);
  }
  if (ans == 0x3f3f3f3f) ans = -1;
  printf("%d\n", ans);
  return 0;
}
