#include <bits/stdc++.h>
using namespace std;
char table[1100][1100];
int used[1100][1100] = {0};
int sum[1100][1100];
int n, m;
int black;
int fy = -1, fx = -1;
int dx[2] = {1, 0};
int dy[2] = {0, 1};
inline int is_valid(int y, int x) { return 0 <= y && y < n && 0 <= x && x < m; }
int dfs(int y, int x) {
  used[y][x] = 1;
  int res = 1;
  for (int i = 0; i < 2; ++i) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if (!used[ny][nx] && is_valid(ny, nx) && table[ny][nx] == 'X') {
      res += dfs(ny, nx);
    }
  }
  return res;
}
inline int get_sum(int x1, int y1, int x2, int y2) {
  assert(x1 <= x2);
  assert(y1 <= y2);
  int res = sum[y2][x2];
  if (y1 > 0) {
    res -= sum[y1 - 1][x2];
  }
  if (x1 > 0) {
    res -= sum[y2][x1 - 1];
  }
  if (y1 > 0 && x1 > 0) {
    res += sum[y1 - 1][x1 - 1];
  }
  return res;
}
inline int can_go(int x, int y, int w, int h) {
  return get_sum(x, y, x + w - 1, y + h - 1) == w * h;
}
int walk(int x, int y, int w, int h) {
  assert(can_go(x, y, w, h));
  int res = w * h;
  int r = 1, b = 1;
  while (r || b) {
    r = can_go(x + 1, y, w, h);
    b = can_go(x, y + 1, w, h);
    if (r && b) {
      return 0;
    }
    if (r) {
      x++;
      res += h;
    }
    if (b) {
      y++;
      res += w;
    }
  }
  return (res == black);
}
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s\n", table[i]);
    for (int j = 0; j < m; ++j) {
      __builtin_prefetch(&table[i][j], 0, 0);
      if (table[i][j] == 'X') {
        if (fy == -1) {
          fy = i;
          fx = j;
        }
        black++;
      }
    }
  }
  if (fy == -1 || dfs(fy, fx) != black) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      sum[i][j] = 0;
      if (i > 0) {
        sum[i][j] += sum[i - 1][j];
      }
      if (j > 0) {
        sum[i][j] += sum[i][j - 1];
      }
      if (i > 0 && j > 0) {
        sum[i][j] -= sum[i - 1][j - 1];
      }
      sum[i][j] += (table[i][j] == 'X');
      __builtin_prefetch(&sum[i][j], 0, 0);
    }
  }
  int fw = 0, fh = 0;
  for (int i = fx; i < m; ++i) {
    if (table[fy][i] == 'X') {
      fw++;
    } else {
      break;
    }
  }
  for (int i = fy; i < n; ++i) {
    if (table[i][fx] == 'X') {
      fh++;
    } else {
      break;
    }
  }
  int res1 = 1234567890;
  int res2 = 1234567890;
  for (int i = 1; i <= fw; ++i) {
    if (walk(fx, fy, i, fh)) {
      res1 = i * fh;
      break;
    }
  }
  for (int i = 1; i <= fh; ++i) {
    if (walk(fx, fy, fw, i)) {
      res2 = i * fw;
      break;
    }
  }
  int res = min(res1, res2);
  printf("%d\n", (res == 1234567890) ? -1 : res);
  return 0;
}
