#include <bits/stdc++.h>
using namespace std;
char str[1010][1010];
int s[1010][1010], n, m, x, y, lx, ly, stx, sty, ans;
bool vis[1010][1010];
int get(int x, int y, int t1, int t2) {
  int ans = 0;
  while (x + t1 <= n && y + t2 <= m && str[x + t1][y + t2] == 'X')
    x += t1, y += t2, ans++;
  return ans;
}
void work(int t1, int t2, int t3, int t4) {
  for (int i = t1; i <= t3; i++)
    for (int j = t2; j <= t4; j++) vis[i][j] = 1;
}
int S(int t1, int t2, int t3, int t4) {
  return s[t3][t4] + s[t1 - 1][t2 - 1] - s[t1 - 1][t4] - s[t3][t2 - 1];
}
bool pd1(int x, int y, int lx, int ly) {
  if (x + lx <= n) {
    return S(x + lx, y, x + lx, y + ly - 1) == ly;
  } else
    return 0;
}
bool pd2(int x, int y, int lx, int ly) {
  if (y + ly <= m) {
    return S(x, y + ly, x + lx - 1, y + ly) == lx;
  } else
    return 0;
}
void solved1() {
  memset(vis, 0, sizeof vis);
  lx = 1;
  ly = get(stx, sty, 0, 1) + 1;
  x = stx, y = sty;
  work(x, y, x + lx - 1, y + ly - 1);
  while (1) {
    while (pd1(x, y, lx, ly) && pd2(x, y, lx, ly))
      lx++, work(x + lx - 1, y, x + lx - 1, y + ly - 1);
    if (pd1(x, y, lx, ly))
      x++, work(x + lx - 1, y, x + lx - 1, y + ly - 1);
    else if (pd2(x, y, lx, ly))
      y++, work(x, y + ly - 1, x + lx - 1, y + ly - 1);
    else
      break;
  }
  memset(vis, 0, sizeof vis);
  x = stx;
  y = sty;
  work(x, y, x + lx - 1, y + ly - 1);
  while (1) {
    if (pd1(x, y, lx, ly))
      x++, work(x + lx - 1, y, x + lx - 1, y + ly - 1);
    else if (pd2(x, y, lx, ly))
      y++, work(x, y + ly - 1, x + lx - 1, y + ly - 1);
    else
      break;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (str[i][j] == 'X' && !vis[i][j]) return;
  ans = lx * ly;
}
void solved2() {
  memset(vis, 0, sizeof vis);
  lx = get(stx, sty, 1, 0) + 1;
  ly = 1;
  x = stx, y = sty;
  work(x, y, x + lx - 1, y + ly - 1);
  while (1) {
    while (pd1(x, y, lx, ly) && pd2(x, y, lx, ly))
      ly++, work(x, y + ly - 1, x + lx - 1, y + ly - 1);
    if (pd2(x, y, lx, ly))
      y++, work(x, y + ly - 1, x + lx - 1, y + ly - 1);
    else if (pd1(x, y, lx, ly))
      x++, work(x + lx - 1, y, x + lx - 1, y + ly - 1);
    else
      break;
  }
  memset(vis, 0, sizeof vis);
  x = stx;
  y = sty;
  work(x, y, x + lx - 1, y + ly - 1);
  while (1) {
    if (pd1(x, y, lx, ly))
      x++, work(x + lx - 1, y, x + lx - 1, y + ly - 1);
    else if (pd2(x, y, lx, ly))
      y++, work(x, y + ly - 1, x + lx - 1, y + ly - 1);
    else
      break;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (str[i][j] == 'X' && !vis[i][j]) return;
  int tt = 0;
  if (ans == -1 || lx * ly < ans) ans = lx * ly;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  for (int i = 1; i <= n; i++) {
    int pdd = 0;
    for (int j = 1; j <= m; j++)
      if (str[i][j] == 'X') {
        stx = i;
        sty = j;
        pdd = 1;
        break;
      }
    if (pdd) break;
  }
  memset(s, 0, sizeof s);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      s[i][j] =
          (str[i][j] == 'X') + s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1];
  ans = -1;
  solved1();
  solved2();
  cout << ans << endl;
  return 0;
}
