#include <bits/stdc++.h>
using namespace std;
bool check(vector<vector<char> > &board, int rows, int columns, int required) {
  if ((rows < 0) || (columns < 0)) return false;
  bool found = false;
  bool ok = true;
  for (int i = 0; (i < board.size()) && (!found); i++) {
    for (int j = 0; (j < board[i].size()) && (!found); j++) {
      if (board[i][j] == 'X') {
        found = true;
        int i_ = i;
        int j_ = j + columns - 1;
        for (int k = i_; (k < i_ + rows) && (ok); k++) {
          for (int l = j_; (l > j_ - columns) && (ok); l--) {
            if (board[k][l] != 'X') {
              ok = false;
            } else {
              required--;
            }
          }
        }
        while ((required > 0) && (ok)) {
          if (board[i_][j_ + 1] == 'X') {
            j_++;
            for (int k = i_; (k < i_ + rows) && (ok); k++) {
              if (board[k][j_] != 'X') {
                ok = false;
              } else {
                required--;
              }
            }
          } else {
            i_++;
            for (int l = j_; (l > j_ - columns) && (ok); l--) {
              if (board[i_ + rows - 1][l] != 'X') {
                ok = false;
              } else {
                required--;
              }
            }
          }
        }
      }
    }
  }
  return ((ok) && (required == 0));
}
void transform(vector<vector<char> > &board) {
  vector<vector<char> > t(board[0].size(), vector<char>(board.size(), '0'));
  for (int i = 1; i <= t.size() - 2; i++) {
    for (int j = 1; j <= t[i].size() - 2; j++) {
      t[i][j] = board[j][i];
    }
  }
  board = t;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  vector<vector<char> > board(n + 2, vector<char>(m + 2, '0'));
  int required = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> board[i][j];
      if (board[i][j] == 'X') required++;
    }
  }
  int solution = INT_MAX;
  for (int trans = 0; trans <= 1; trans++) {
    if (trans) transform(board);
    bool found = false;
    int columns = 1, rows = 1;
    for (int i = 0; (i < board.size()) && (!found); i++) {
      for (int j = 0; (j < board[i].size()) && (!found); j++) {
        if (board[i][j] == 'X') {
          found = true;
          int i_ = i, j_ = j;
          int sumRow = 0;
          bool turnRight = false;
          while (board[i_][j_] == 'X') {
            if (board[i_][j_ + 1] == 'X') {
              if (sumRow != 0) {
                turnRight = true;
                rows += sumRow;
                break;
              }
              columns++;
              j_++;
            } else {
              sumRow--;
              i_++;
            }
          }
          if (turnRight) {
            while (board[i + 1][j] == 'X') {
              i++;
              rows++;
            }
          } else {
            rows = 1;
          }
        }
      }
    }
    if (check(board, rows, columns, required)) {
      solution = min(solution, rows * columns);
    }
  }
  solution = (solution == INT_MAX) ? -1 : solution;
  cout << solution << endl;
  return 0;
}
