#include <bits/stdc++.h>
using namespace std;
const int N = 1200;
int n, m;
char a[N][N];
int x, y;
bool was[N][N];
int dx[5] = {0, 0, 1, -1};
int dy[5] = {1, -1, 0, 0};
bool ok(int x, int y) {
  if (x > 0 && y > 0 && x <= n && y <= m) return 1;
  return 0;
}
void dfs(int x, int y) {
  was[x][y] = 1;
  for (int i = 0; i < 4; ++i) {
    int nx = dx[i] + x;
    int ny = dy[i] + y;
    if (ok(nx, ny) && !was[nx][ny]) dfs(nx, ny);
  }
}
int minX = 1000 * 1000 * 1000, minY = 1000 * 1000 * 1000,
    maxX = -1000 * 1000 * 1000, maxY = -1000 * 1000 * 1000;
int L[N], R[N];
int nL[N], nR[N], sum[N][N];
int get(int x, int y, int x2, int y2) {
  return sum[x2][y2] - sum[x - 1][y2] - sum[x2][y - 1] + sum[x - 1][y - 1];
}
bool can(int H, int W) {
  if (!ok(x + H - 1, y + W - 1)) return 0;
  int posX = x, posY = y;
  bool is = 1;
  int total = H * W;
  while (is) {
    is = 0;
    if (posX + H <= n && get(posX + H, posY, posX + H, posY + W - 1) == W) {
      total += W;
      posX++;
      is = 1;
    } else if (posY + W <= m &&
               get(posX, posY + W, posX + H - 1, posY + W) == H) {
      total += H;
      posY++;
      is = 1;
    } else {
      break;
    }
  }
  if (total == sum[n][m]) return 1;
  return 0;
}
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      scanf("%c", &a[i][j]);
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      if (a[i][j] == 'X') {
        minX = min(minX, i);
        maxX = max(maxX, i);
        minY = min(minY, j);
        maxY = max(maxY, j);
        sum[i][j]++;
      }
      if (a[i][j] == 'X' && !x) {
        x = i, y = j;
      }
    }
    scanf("\n");
  }
  if (!x) {
    puts("-1");
    return 0;
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (!was[i][j]) ++cnt, dfs(i, j);
    }
  }
  if (cnt > 1) {
    puts("-1");
    return 0;
  }
  bool ok = 1;
  for (int i = minX; i <= maxX; ++i) {
    for (int j = minY; j <= maxY; ++j) {
      if (a[i][j] != 'X') {
        ok = 0;
      }
    }
  }
  if (ok) {
    cout << min(maxX - minX + 1, maxY - minY + 1);
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (a[i][j] == 'X') {
        R[i] = j;
        if (!L[i]) L[i] = j;
      }
    }
    if (L[i]) {
      for (int j = L[i]; j <= R[i]; ++j) {
        if (a[i][j] != 'X') {
          puts("-1");
          return 0;
        }
      }
    }
  }
  int right = 1, down = 1;
  while (x + down <= n && a[x + down][y] == 'X') ++down;
  while (y + right <= m && a[x][y + right] == 'X') ++right;
  int ans = 1000 * 1000 * 1000;
  for (int i = 1; i <= down; ++i) {
    if (can(i, right)) ans = min(ans, i * right);
  }
  for (int i = 1; i <= right; ++i) {
    if (can(down, i)) ans = min(ans, down * i);
  }
  if (ans == 1000 * 1000 * 1000)
    puts("-1");
  else
    cout << ans;
  return 0;
}
