#include <bits/stdc++.h>
using namespace std;
char x[1005][1005];
int sum[1005][1005];
int r, c, h, w, cnt;
int getRangeSum(int a, int b, int c, int d) {
  return sum[c][d] - sum[a - 1][d] - sum[c][b - 1] + sum[a - 1][b - 1];
}
int dfs(int p, int q) {
  if (q + w <= c && getRangeSum(p, q + w, p + h - 1, q + w) == h)
    return h + dfs(p, q + 1);
  if (p + h <= r && getRangeSum(p + h, q, p + h, q + w - 1) == w)
    return w + dfs(p + 1, q);
  return 0;
}
void solve() {
  for (int i = 1; i <= r; i++)
    for (int j = 1; j <= c; j++) {
      sum[i][j] = (x[i][j] == 'X' ? 1 : 0) + sum[i - 1][j] + sum[i][j - 1] -
                  sum[i - 1][j - 1];
      cnt += (x[i][j] == 'X' ? 1 : 0);
    }
  int ans = 1e9;
  for (int i = 1; i <= r; i++)
    for (int j = 1; j <= c; j++)
      if (x[i][j] == 'X') {
        int k = j + 1, b = 1;
        while (k <= c && x[i][k] == x[i][j]) k++, b++;
        w = b;
        for (h = 1; i + h - 1 <= r; h++)
          if (getRangeSum(i, j, i + h - 1, j + w - 1) == h * w &&
              dfs(i, j) == cnt - h * w)
            ans = min(ans, w * h);
        k = i + 1;
        b = 1;
        while (k <= r && x[k][j] == x[i][j]) k++, b++;
        h = b;
        for (w = 1; j + w <= c; w++)
          if (getRangeSum(i, j, i + h - 1, j + w - 1) == h * w &&
              dfs(i, j) == cnt - h * w)
            ans = min(ans, w * h);
        if (ans == 1e9)
          puts("-1");
        else
          printf("%d\n", ans);
        return;
      }
}
int main() {
  scanf("%d%d", &r, &c);
  for (int i = 1; i <= r; i++)
    for (int j = 0; j <= c; j++) scanf("%c", &x[i][j]);
  solve();
}
