#include <bits/stdc++.h>
using namespace std;
int w, h;
int n, m;
int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, -1, 1};
int vis[1005][1005], visID;
bool g[1005][1005];
int cum[1005][1005];
int count(int x1, int y1, int h, int w) {
  int x2 = x1 + h - 1;
  int y2 = y1 + w - 1;
  x2 = min(x2, n);
  y2 = min(y2, m);
  return cum[x2][y2] - cum[x1 - 1][y2] - cum[x2][y1 - 1] + cum[x1 - 1][y1 - 1];
}
bool check(int i, int j) {
  if (i < 1 || i + h - 1 > n || j < 1 || j + w - 1 > m ||
      count(i, j, h, w) != h * w)
    return 0;
  bool ret = 1;
  int down = count(i + h, j, 1, w);
  int right = count(i, j + w, h, 1);
  if (down == w && right == h) return 0;
  if (down == w) {
    for (int k = 0; k < w; k++) vis[i + h][j + k] = visID;
    return check(i + 1, j);
  }
  if (right == h) {
    for (int k = 0; k < h; k++) vis[i + k][j + w] = visID;
    return check(i, j + 1);
  }
  return (!down && !right);
}
bool valid(int i, int j) {
  visID++;
  for (int ii = 0; ii < h; ii++)
    for (int jj = 0; jj < w; jj++) vis[i + ii][j + jj] = visID;
  if (!check(i, j)) return 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (vis[i][j] != visID && g[i][j]) return 0;
  return 1;
}
void h_fixed(int i, int j) {
  if (i < 1 || i + h - 1 > n || j < 1 || j + w - 1 > m ||
      count(i, j, h, w) != h * w)
    return;
  int down = count(i + h, j, 1, w);
  int right = count(i, j + w, h, 1);
  while (down == w && right == h) {
    w++;
    down = count(i + h, j, 1, w);
    right = count(i, j + w, h, 1);
  }
  if (!down && right == h) {
    h_fixed(i, j + 1);
    return;
  }
  if (down == w && !right) {
    h_fixed(i + 1, j);
    return;
  }
}
void w_fixed(int i, int j) {
  if (i < 0 || i + h - 1 >= n || j < 0 || j + w - 1 >= m ||
      count(i, j, h, w) != h * w)
    return;
  int down = count(i + h, j, 1, w);
  int right = count(i, j + w, h, 1);
  while (down == w && right == h) {
    h++;
    down = count(i + h, j, 1, w);
    right = count(i, j + w, h, 1);
  }
  if (!down && right == h) {
    w_fixed(i, j + 1);
    return;
  }
  if (down == w && !right) {
    w_fixed(i + 1, j);
    return;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  bool found = 0;
  cin >> n >> m;
  int x, y;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      g[i][j] = (c == 'X');
      if (!found && g[i][j]) {
        found = 1;
        x = i, y = j;
      }
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      cum[i][j] = g[i][j] + cum[i - 1][j] + cum[i][j - 1] - cum[i - 1][j - 1];
  h = 0, w = 1;
  const int inf = 1e9;
  int area = inf;
  for (int i = x; i <= n && g[i][y]; i++) h++;
  h_fixed(x, y);
  if (valid(x, y)) area = h * w;
  h = 1, w = 0;
  for (int i = y; i <= m && g[x][i]; i++) w++;
  w_fixed(x, y);
  if (valid(x, y)) area = min(area, h * w);
  if (area == inf) area = -1;
  cout << area << "\n";
  return 0;
}
