#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
int vis[1005][1005];
char a[1005][1005];
int deex(int x, int y) {
  int i, cnt = 0;
  for (i = x; i >= 0 && a[i][y] == 'X'; --i) cnt++;
  return cnt;
}
int deey(int x, int y) {
  int j, cnt = 0;
  for (j = y; j >= 0 && a[x][j] == 'X'; --j) cnt++;
  return cnt;
}
int ans;
bool canmovex(int x, int y, int d) {
  int i = 0;
  for (i = x; i > x - d; --i)
    if (a[i][y] != 'X') return 0;
  return 1;
}
bool canmovey(int x, int y, int d) {
  int j = 0;
  for (j = y; j > y - d; --j)
    if (a[x][j] != 'X') return 0;
  return 1;
}
void bfs1(int sx, int sy) {
  int i, j, k, flag;
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j) vis[i][j] = 0;
  for (i = sx; i >= 0 && a[i][sy] == 'X'; --i) vis[i][sy] = 1;
  i = sx, j = sy;
  while (1) {
    flag = 0;
    for (; j < m - 1; ++j)
      if (canmovex(i, j + 1, x)) {
        flag = 1;
        for (k = i; k > i - x; --k) vis[k][j + 1] = 1;
      } else
        break;
    for (; i < n - 1; ++i) {
      if (a[i + 1][j] == 'X' && (y == 0 || canmovey(i + 1, j, y))) {
        flag = 1;
        if (!y) y = deey(i + 1, j);
        for (k = j; k > j - y; --k) vis[i + 1][k] = 1;
      } else
        break;
    }
    if (!flag) break;
  }
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j)
      if ((a[i][j] == 'X' && vis[i][j] == 0) ||
          (a[i][j] == '.' && vis[i][j] == 1))
        return;
  if (y == 0)
    ans = x;
  else
    ans = x * y;
}
void bfs2(int sx, int sy) {
  int i, j, k, flag;
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j) vis[i][j] = 0;
  for (i = sy; i >= 0 && a[sx][i] == 'X'; --i) vis[sx][i] = 1;
  i = sx, j = sy;
  while (1) {
    flag = 0;
    for (; i < n - 1; ++i) {
      if (canmovey(i + 1, j, y)) {
        flag = 1;
        for (k = j; k > j - y; --k) vis[i + 1][k] = 1;
      } else
        break;
    }
    for (; j < m - 1; ++j)
      if (a[i][j + 1] == 'X' && (x == 0 || canmovex(i, j + 1, x))) {
        if (!x) x = deex(i, j + 1);
        flag = 1;
        for (k = i; k > i - x; --k) vis[k][j + 1] = 1;
      } else
        break;
    if (!flag) break;
  }
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j)
      if ((a[i][j] == 'X' && vis[i][j] == 0) ||
          (a[i][j] == '.' && vis[i][j] == 1))
        return;
  if (x == 0) {
    if (ans == -1)
      ans = y;
    else
      ans = min(ans, y);
  } else {
    if (ans == -1)
      ans = x * y;
    else
      ans = min(ans, x * y);
  }
}
int main() {
  int i, j, sx, sy;
  while (scanf("%d%d", &n, &m) != EOF) {
    ans = -1;
    for (i = 0; i < n; ++i) scanf("%s", a[i]);
    for (i = 0; i < n; ++i) {
      for (j = 0; j < m; ++j)
        if (a[i][j] == 'X') {
          sx = i;
          sy = j;
          break;
        }
      if (j < m) break;
    }
    x = 0;
    y = 0;
    for (i = sx, j = sy; i < n && a[i][j] == 'X'; ++i) x++;
    bfs1(sx + x - 1, sy);
    x = 0;
    y = 0;
    for (j = sy, i = sx; j < m && a[i][j] == 'X'; ++j) y++;
    bfs2(sx, sy + y - 1);
    printf("%d\n", ans);
  }
  return 0;
}
