#include <bits/stdc++.h>
using namespace std;
int n, m;
bool correct(vector<string> grid, int sr, int sc, int h, int w, bool valid) {
  if (sr + h > n || sc + w > m) return false;
  for (int i = sr; i < sr + h; ++i)
    for (int j = sc; j < sc + w; ++j) {
      if (valid && grid[i][j] == '.') return false;
      grid[i][j] = '.';
    }
  while (true) {
    int way = 0;
    if (sc + w < m && grid[sr][sc + w] == 'X')
      way = 1;
    else if (sr + h < n && grid[sr + h][sc] == 'X')
      way = 2;
    else if (sc + w < m && !valid)
      way = 1;
    else if (sr + h < n && !valid)
      way = 2;
    else
      break;
    if (way == 1) {
      for (int i = sr; i < sr + h; ++i) {
        if (valid && grid[i][sc + w] == '.') return false;
        grid[i][sc + w] = '.';
      }
      sc++;
    } else {
      for (int j = sc; j < sc + w; ++j) {
        if (valid && grid[sr + h][j] == '.') return false;
        grid[sr + h][j] = '.';
      }
      sr++;
    }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (grid[i][j] != '.') return false;
  return true;
}
int check(vector<string> grid) {
  int sr = -1, sc, h = 1, w = 1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (sr == -1 && grid[i][j] == 'X') sr = i, sc = j;
  if (sr == -1) return 1e7;
  vector<string> cgrid = grid;
  int csr = sr, csc = sc;
  while (sr + h < n && grid[sr + h][sc] == 'X') h++;
  for (int i = sr; i < sr + h; ++i) {
    if (grid[i][sc] == '.') return 1e7;
    grid[i][sc] = '.';
  }
  while ((sc + w < m && grid[sr][sc + w] == 'X') ||
         (sr + h < n && grid[sr + h][sc] == 'X')) {
    if (sc + w < m && grid[sr][sc + w] == 'X') {
      for (int i = sr; i < sr + h; ++i) {
        if (grid[i][sc + w] == '.') return 1e7;
        grid[i][sc + w] = '.';
      }
      if (sr + h < n && grid[sr + h][sc] == 'X')
        w++;
      else
        sc++;
    } else {
      for (int j = sc; j < sc + w; ++j) {
        if (grid[sr + h][j] == '.') return 1e7;
        grid[sr + h][j] = '.';
      }
      sr++;
    }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (grid[i][j] == 'X') return 1e7;
  if (!correct(cgrid, csr, csc, h, w, 1)) return 1e7;
  return h * w;
}
int main() {
  cin >> n >> m;
  vector<string> grid(n);
  for (int i = 0; i < n; ++i) {
    cin >> grid[i];
  }
  int ans = 1e7;
  ans = min(ans, check(grid));
  vector<string> invert(m);
  for (int i = 0; i < m; ++i) invert[i].resize(n);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) invert[j][i] = grid[i][j];
  swap(n, m);
  ans = min(ans, check(invert));
  if (ans > 1e6)
    cout << "-1\n";
  else
    cout << ans << '\n';
}
