#include <bits/stdc++.h>
using namespace std;
const int MX = 1024;
int N, M;
char mp[MX][MX];
int sumh[MX][MX], sumw[MX], fst[MX];
pair<int, int> st;
int get_wide(int h) {
  int x = st.first + h - 1;
  int y = st.second;
  int w = 1;
  while (true) {
    if (y + 1 < M && sumh[x][y + 1] >= h) {
      y++;
    } else if (x + 1 < N && mp[x + 1][y] == 'X') {
      x++;
      int nw = y - fst[x] + 1;
      if (nw > w) w = nw;
    } else {
      break;
    }
  }
  return w;
}
int line[MX];
void plus_line(int l, int r, int v) {
  line[l] += v;
  line[r + 1] -= v;
}
bool check(int h, int w) {
  memset((line), 0, sizeof(line));
  int x = st.first + h - 1;
  int y = st.second + w - 1;
  plus_line(st.first, x, w);
  while (true) {
    if (y + 1 < M && sumh[x][y + 1] == h) {
      y++;
      plus_line(x - h + 1, x, 1);
    } else if (x + 1 < N && mp[x + 1][y] == 'X') {
      x++;
      plus_line(x, x, w);
    } else {
      break;
    }
  }
  if (sumw[0] != line[0]) return false;
  for (int i = 1; i < N; i++) {
    line[i] += line[i - 1];
    if (sumw[i] != line[i]) return false;
  }
  return true;
}
int main() {
  st = make_pair(-1, -1);
  memset((sumw), 0, sizeof(sumw));
  memset((sumh), 0, sizeof(sumh));
  memset((fst), -1, sizeof(fst));
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%s", mp[i]);
    for (int j = 0; j < M; j++) {
      if (mp[i][j] == 'X') {
        if (st.first == -1) st = make_pair(i, j);
        if (fst[i] == -1) fst[i] = j;
        sumw[i]++;
        if (i)
          sumh[i][j] = sumh[i - 1][j] + 1;
        else
          sumh[i][j] = 1;
      }
    }
  }
  if (st.first == -1) {
    puts("0");
    return 0;
  }
  int ans = -1;
  for (int h = 1; h <= N; h++) {
    int w = get_wide(h);
    if (check(h, w) && (ans == -1 || ans > h * w)) ans = h * w;
  }
  printf("%d\n", ans);
  return 0;
}
