#include <bits/stdc++.h>
using namespace std;
int n, m;
char mat[1005][1005];
char tmp[1005][1005];
bool ck(int W, int H) {
  memset(tmp, '.', sizeof(tmp));
  int yr, xr, yv, xv, yh, xh;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (mat[i][j] == 'X') {
        yr = i + H - 1, xr = j + W - 1;
        yv = i, xv = j + W - 1;
        yh = i + H - 1, xh = j;
        for (int y = 0; y < H; ++y)
          for (int x = 0; x < W; ++x) tmp[i + y][j + x] = 'X';
        goto exit;
      }
exit:;
  while (true) {
    if (xr + 1 < m && mat[yr][xr + 1] == 'X' && mat[yv][xv + 1] == 'X') {
      xr++, xv++, xh++;
      for (int i = yv; i <= yr; ++i) tmp[i][xr] = 'X';
    } else if (yr + 1 < n && mat[yr + 1][xr] == 'X' && mat[yh + 1][xh] == 'X') {
      yr++, yv++, yh++;
      for (int j = xh; j <= xr; ++j) tmp[yr][j] = 'X';
    } else
      break;
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (mat[i][j] != tmp[i][j]) return 0;
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", mat[i]);
  int W = 0, H = 0, totalCnt = 0;
  for (int i = 0; i < n; ++i) {
    int cnt = count(mat[i], mat[i] + m, 'X');
    if (cnt) {
      W = cnt;
      break;
    }
  }
  for (int j = 0; j < m; ++j) {
    int cnt = 0;
    for (int i = 0; i < n; ++i) cnt += (mat[i][j] == 'X');
    if (cnt) {
      H = cnt;
      break;
    }
  }
  int mn_y = 10000, mx_y = -10000;
  int mn_x = 10000, mx_x = -10000;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      totalCnt += (mat[i][j] == 'X');
      if (mat[i][j] == 'X') {
        mn_y = min(mn_y, i);
        mx_y = max(mx_y, i);
        mn_x = min(mn_x, j);
        mx_x = max(mx_x, j);
      }
    }
  int lenW = mx_x - mn_x + 1;
  int lenH = mx_y - mn_y + 1;
  int ans = 100000000;
  for (int nH = 1; nH <= n; ++nH) {
    int total = (lenW - W) * nH + (lenH - nH) * W + W * nH;
    if (total == totalCnt && ck(W, nH)) {
      ans = min(ans, W * nH);
      break;
    }
  }
  for (int nW = 1; nW <= m; ++nW) {
    int total = (lenW - nW) * H + (lenH - H) * nW + nW * H;
    if (total == totalCnt && ck(nW, H)) {
      ans = min(ans, nW * H);
      break;
    }
  }
  printf("%d", ans == 100000000 ? -1 : ans);
}
