#include <bits/stdc++.h>
using namespace std;
char a[1100][1100];
int xia[1100][1100];
int you[1100][1100];
int ans;
int main() {
  int i, j, m, n, tot, b1, you1, xia1, now, xia2, you2, x, y, xx, yy, cnt;
  scanf("%d%d", &m, &n);
  for (i = 0; i < m; i++) scanf("%s", a[i]);
  memset(xia, 0, sizeof(xia));
  memset(you, 0, sizeof(you));
  tot = 0;
  for (i = m - 1; i >= 0; i--)
    for (j = n - 1; j >= 0; j--) {
      xia[i][j] = 0;
      you[i][j] = 0;
      if (a[i][j] == 'X') {
        xia[i][j] = xia[i + 1][j] + 1;
        you[i][j] = you[i][j + 1] + 1;
        tot++;
      }
    }
  b1 = 0;
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++)
      if (a[i][j] == 'X') {
        x = i;
        y = j;
        b1 = 1;
        break;
      }
    if (b1 == 1) break;
  }
  ans = 2000000000;
  xia1 = xia[x][y];
  you1 = you[x][y];
  for (i = 0; i < xia1; i++) {
    if (you[x + i][y] < you1) break;
    now = you1 * (i + 1);
    xx = x;
    yy = y;
    you2 = you1;
    xia2 = i + 1;
    b1 = 1;
    while (1) {
      cnt = 0;
      if ((xx + xia2 < m) && (a[xx + xia2][yy] == 'X')) cnt |= 1;
      if ((yy + you2 < n) && (a[xx][yy + you2] == 'X')) cnt |= 2;
      if (cnt == 3) {
        b1 = 0;
        break;
      }
      if (cnt == 0) break;
      if (cnt == 1) {
        if (you[xx + xia2][yy] >= you2) {
          xx++;
          now += you2;
        } else {
          b1 = 0;
          break;
        }
      } else {
        if (xia[xx][yy + you2] >= xia2) {
          yy++;
          now += xia2;
        } else {
          b1 = 0;
          break;
        }
      }
    }
    if (now != tot) b1 = 0;
    if (b1 == 1) {
      if (you1 * (i + 1) < ans) ans = you1 * (i + 1);
    }
  }
  for (i = 0; i < you1; i++) {
    if (xia[x][y + i] < xia1) break;
    now = xia1 * (i + 1);
    xx = x;
    yy = y;
    you2 = i + 1;
    xia2 = xia1;
    b1 = 1;
    while (1) {
      cnt = 0;
      if ((xx + xia2 < m) && (a[xx + xia2][yy] == 'X')) cnt |= 1;
      if ((yy + you2 < n) && (a[xx][yy + you2] == 'X')) cnt |= 2;
      if (cnt == 3) {
        b1 = 0;
        break;
      }
      if (cnt == 0) break;
      if (cnt == 1) {
        if (you[xx + xia2][yy] >= you2) {
          xx++;
          now += you2;
        } else {
          b1 = 0;
          break;
        }
      } else {
        if (xia[xx][yy + you2] >= xia2) {
          yy++;
          now += xia2;
        } else {
          b1 = 0;
          break;
        }
      }
    }
    if (now != tot) b1 = 0;
    if (b1 == 1) {
      if (xia1 * (i + 1) < ans) ans = xia1 * (i + 1);
    }
  }
  if (ans == 2000000000)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
