#include <bits/stdc++.h>
using namespace std;
int n, m, sr, second;
char arr[1005][1005], arr2[1005][1005];
bool cd(int cr, int cc, int h, int w) {
  if (cr + h == n) return false;
  return arr[cr + h][cc] == 'X';
}
bool cr(int cr, int cc, int h, int w) {
  if (cc + w == m) return false;
  return arr[cr][cc + w] == 'X';
}
void fill(int r, int c, int h, int w) {
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) arr2[r + i][c + j] = 'X';
}
void paint(int sr, int second, int h, int w) {
  memset(arr2, '.', sizeof(arr2));
  ;
  fill(sr, second, h, w);
  while (1) {
    if (cd(sr, second, h, w))
      ++sr, fill(sr + h - 1, second, 1, w);
    else if (cr(sr, second, h, w))
      ++second, fill(sr, second + w - 1, h, 1);
    else
      break;
  }
}
bool same() {
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (arr[i][j] != arr2[i][j]) return false;
  return true;
}
int solve() {
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (arr[i][j] == 'X') {
        sr = i, second = j;
        i = n;
        break;
      }
    }
  int w = 0;
  while (second + w < m && arr[sr][second + w] == 'X') ++w;
  int h1 = 0, h2 = -1;
  while (sr + h1 < n && arr[sr + h1][second] == 'X') ++h1;
  if (second + w == m) {
    h2 = -1;
  } else {
    for (int i = 0; sr + i < n; ++i) {
      if (arr[sr + i][second + w] == 'X') {
        h2 = i;
        break;
      }
    }
  }
  int h;
  if (h2 == -1)
    h = 1;
  else
    h = h1 - h2;
  if (h < 1) h = 1;
  paint(sr, second, h, w);
  if (!same()) return 1000000006;
  return w * h;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", arr[i]);
  int ans = solve();
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) arr2[i][j] = arr[i][j];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) arr[j][i] = arr2[i][j];
  swap(n, m);
  ans = min(ans, solve());
  if (ans == 1000000006) ans = -1;
  printf("%d\n", ans);
  return 0;
}
