#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 5;
const int inf = 1e8;
char maze[maxn][maxn];
int Row[maxn], Col[maxn];
int sum_col[maxn][maxn];
int sum_row[maxn][maxn];
int n, m;
void RightFirst(int r, int c, int& h, int& w) {
  if (Col[c - 1] > 0) return;
  h = 1;
  while (r + h <= n && maze[r + h][c] == '#') ++h;
  w = 1;
  for (int i = c; i <= m; ++i) {
    if (sum_col[i][r] == 0) break;
    if (sum_col[i][r] < h)
      return;
    else if (sum_col[i][r] > h) {
      c = i;
      while (c + w <= m && maze[r][c + w] == '#') ++w;
      break;
    }
  }
}
void DownFirst(int r, int c, int& h, int& w) {
  if (Row[r - 1] > 0) return;
  w = h = 1;
  while (c + w <= m && maze[r][c + w] == '#') ++w;
  for (int i = r; i <= n; ++i) {
    if (sum_row[i][c] == 0) break;
    if (sum_row[i][c] < w)
      return;
    else if (sum_row[i][c] > w) {
      r = i;
      while (r + h <= n && maze[r + h][c] == '#') ++h;
      break;
    }
  }
}
bool vis[maxn][maxn];
bool Ok(int r, int c, int h, int w) {
  memset(vis, 0, sizeof(vis));
  for (int i = (r); i < (int)(r + h); ++i)
    for (int j = (c); j < (int)(c + w); ++j) {
      vis[i][j] = true;
      if (maze[i][j] != '#') return false;
    }
  for (;;) {
    if (r + h <= n && maze[r + h][c] == '#') {
      for (int j = (c); j < (int)(c + w); ++j) {
        vis[r + h][j] = true;
        if (maze[r + h][j] != '#') return false;
      }
      ++r;
    } else if (c + w <= m && maze[r][c + w] == '#') {
      for (int i = (r); i < (int)(r + h); ++i) {
        vis[i][c + w] = true;
        if (maze[i][c + w] != '#') return false;
      }
      ++c;
    } else
      break;
  }
  for (int i = (1); i < (int)(n + 1); ++i)
    for (int j = (1); j < (int)(m + 1); ++j)
      if (maze[i][j] == '#' && !vis[i][j]) return false;
  return true;
}
int main() {
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = (1); i < (int)(n + 1); ++i) {
      scanf("%s", maze[i] + 1);
      for (int j = (1); j < (int)(m + 1); ++j)
        if (maze[i][j] == 'X') maze[i][j] = '#';
      for (int j = (1); j < (int)(m + 1); ++j)
        if (maze[i][j] == '#') {
          ++Row[i], ++Col[j];
          ++sum_row[i][j];
          ++sum_col[j][i];
          if (j == 2 && i == 4) char a = 'a';
        }
      for (int j = (m - 1); j >= (int)(0); --j)
        sum_row[i][j] += sum_row[i][j + 1];
    }
    for (int j = (1); j < (int)(m + 1); ++j)
      for (int i = (n - 1); i >= (int)(1); --i)
        sum_col[j][i] += sum_col[j][i + 1];
    for (int i = (1); i < (int)(n); ++i) Row[i] += Row[i - 1];
    for (int j = (1); j < (int)(m); ++j) Col[j] += Col[j - 1];
    int r = -1, c = -1;
    for (int i = (1); i < (int)(n + 1); ++i) {
      for (int j = (1); j < (int)(m + 1); ++j)
        if (maze[i][j] == '#') {
          r = i;
          c = j;
          break;
        }
      if (r != -1) break;
    }
    int ans = inf;
    int h = 1, w = 1;
    DownFirst(r, c, h, w);
    if (Ok(r, c, h, w)) ans = min(ans, h * w);
    RightFirst(r, c, h, w);
    if (Ok(r, c, h, w)) ans = min(ans, h * w);
    if (ans == inf)
      puts("-1");
    else
      printf("%d\n", ans);
  }
}
