#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 4e18;
const int inf = 2e9;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int dp[1005][1005];
char s[1005][1005];
inline int take(int i, int j, int ii, int jj) {
  return dp[ii][jj] - dp[ii][j - 1] - dp[i - 1][jj] + dp[i - 1][j - 1];
}
int main(void) {
  int i, j, n, m;
  pair<int, int> st = make_pair(inf, inf), fn = make_pair(-1, -1);
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; ++i) scanf("%s", &s[i][1]);
  int ans = inf, tot = 0;
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) {
      dp[i][j] = (s[i][j] == 'X');
      dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      if (s[i][j] == 'X') {
        st = min(st, make_pair(i, j));
        fn = max(fn, make_pair(i, j));
        tot++;
      }
    }
  int lefi = st.first, lefj = st.second;
  int rigi = fn.first, rigj = fn.second;
  int row = inf, col = inf;
  for (j = 1; j <= m; ++j) {
    bool udah = 0;
    int temp = 0;
    for (i = 1; i <= n; ++i) {
      if (s[i][j] != 'X' && s[i - 1][j] == 'X') break;
      temp += (s[i][j] == 'X');
    }
    if (temp == 0) continue;
    row = min(row, temp);
  }
  for (i = 1; i <= n; ++i) {
    bool udah = 0;
    int temp = 0;
    for (j = 1; j <= m; ++j) {
      if (s[i][j] != 'X' && s[i][j - 1] == 'X') break;
      temp += (s[i][j] == 'X');
    }
    if (temp == 0) continue;
    col = min(col, temp);
  }
  int asi, asj;
  for (asi = 1; asi <= row; ++asi)
    for (asj = 1; asj <= col; ++asj) {
      int i = lefi + asi - 1;
      int j = lefj + asj - 1;
      bool valid = 1;
      int token = 0;
      while (!(i == rigi && j == rigj)) {
        int remrig = take(i - asi + 1, j + 1, i, j + 1);
        int remdow = take(i + 1, j - asj + 1, i + 1, j);
        if (remrig == asi) {
          if (remdow == asj) {
            valid = 0;
            break;
          }
          token += asi;
          j++;
        } else if (remdow == asj) {
          if (remrig == asi) {
            valid = 0;
            break;
          }
          token += asj;
          i++;
        } else {
          valid = 0;
          break;
        }
      }
      token += asi * asj;
      if (valid && token == tot) {
        ans = min(ans, asi * asj);
      }
    }
  cout << (ans == inf ? -1 : ans) << endl;
  return 0;
}
