#include <bits/stdc++.h>
using namespace std;
const int MN = 1011;
const int inf = 1000111000;
const int di[] = {-1, 1, 0, 0};
const int dj[] = {0, 0, -1, 1};
int m, n;
char a[MN][MN], b[MN][MN];
bool visited[MN][MN];
int first[MN][MN], last[MN][MN], sum[MN][MN];
void rotate() {
  for (int i = (1), _b = (m); i <= _b; i++)
    for (int j = (1), _b = (n); j <= _b; j++) b[i][j] = a[i][j];
  memset(a, ' ', sizeof a);
  swap(m, n);
  for (int i = (1), _b = (m); i <= _b; i++)
    for (int j = (1), _b = (n); j <= _b; j++) a[i][j] = b[j][i];
}
void init() {
  memset(sum, 0, sizeof sum);
  memset(first, 0, sizeof first);
  memset(last, 0, sizeof last);
  for (int i = (1), _b = (m); i <= _b; i++)
    for (int j = (1), _b = (n); j <= _b; j++)
      sum[i][j] = sum[i - 1][j] + ((a[i][j] == 'X') ? 1 : 0);
  for (int i = (1), _b = (m); i <= _b; i++) {
    for (int j = (1), _b = (n); j <= _b; j++)
      if (a[i][j] == 'X') {
        if (a[i - 1][j] == 'X')
          first[i][j] = first[i - 1][j];
        else
          first[i][j] = i;
      }
  }
  for (int i = (m), _b = (1); i >= _b; i--) {
    for (int j = (1), _b = (n); j <= _b; j++)
      if (a[i][j] == 'X') {
        if (a[i + 1][j] == 'X')
          last[i][j] = last[i + 1][j];
        else
          last[i][j] = i;
      }
  }
}
int check() {
  init();
  for (int j = (1), _b = (n); j <= _b; j++) {
    for (int i = (1), _b = (m); i <= _b; i++)
      if (a[i][j] == 'X') {
        if (sum[m][j] != last[i][j] - first[i][j] + 1) return inf;
        int height = sum[m][j];
        int i1 = i, i2 = i + height - 1;
        int j1 = j, j2 = j1;
        for (int i = (1), _b = (m); i <= _b; i++)
          for (int j = (1), _b = (n); j <= _b; j++) b[i][j] = a[i][j];
        bool canExtend = true;
        for (int i = (i1), _b = (i2); i <= _b; i++)
          for (int j = (j1), _b = (j2); j <= _b; j++) b[i][j] = '.';
        while (b[i1][j2 + 1] == 'X' || b[i2 + 1][j1] == 'X') {
          if (b[i1][j2 + 1] == 'X' && b[i2 + 1][j1] == 'X') {
            if (!canExtend) return inf;
            for (int i = (i1), _b = (i2); i <= _b; i++) {
              if (b[i][j2 + 1] == '.') return inf;
              b[i][j2 + 1] = '.';
            }
            ++j2;
          } else if (b[i1][j2 + 1] == 'X') {
            for (int i = (i1), _b = (i2); i <= _b; i++) {
              if (b[i][j2 + 1] == '.') return inf;
              b[i][j2 + 1] = '.';
            }
            ++j1;
            ++j2;
          } else {
            canExtend = false;
            for (int j = (j1), _b = (j2); j <= _b; j++) {
              if (b[i2 + 1][j] == '.') return inf;
              b[i2 + 1][j] = '.';
            }
            ++i1;
            ++i2;
          }
        }
        for (int i = (1), _b = (m); i <= _b; i++)
          for (int j = (1), _b = (n); j <= _b; j++)
            if (b[i][j] == 'X') return inf;
        return (i2 - i1 + 1) * (j2 - j1 + 1);
      }
  }
  return inf;
}
void solve() {
  memset(visited, false, sizeof visited);
  int components = 0;
  for (int i = (1), _b = (m); i <= _b; i++)
    for (int j = (1), _b = (n); j <= _b; j++)
      if (!visited[i][j] && a[i][j] == 'X') {
        ++components;
        if (components > 1) {
          cout << -1 << endl;
          return;
        }
        queue<pair<int, int> > qu;
        qu.push(make_pair(i, j));
        visited[i][j] = true;
        while (!qu.empty()) {
          int u = qu.front().first, v = qu.front().second;
          qu.pop();
          for (int dir = 0, _a = (4); dir < _a; dir++) {
            int uu = u + di[dir], vv = v + dj[dir];
            if (a[uu][vv] == 'X' && !visited[uu][vv]) {
              qu.push(make_pair(uu, vv));
              visited[uu][vv] = true;
            }
          }
        }
      }
  int res = inf;
  res = min(res, check());
  rotate();
  res = min(res, check());
  if (res == inf) res = -1;
  cout << res << endl;
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(NULL);
  cout << (fixed) << setprecision(6);
  while (cin >> m >> n) {
    bool hasX = false;
    for (int i = (1), _b = (m); i <= _b; i++)
      for (int j = (1), _b = (n); j <= _b; j++) {
        cin >> a[i][j];
        if (a[i][j] == 'X') hasX = true;
      }
    if (!hasX) {
      cout << -1 << endl;
      continue;
    }
    solve();
  }
  return 0;
}
