#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
char tab[N][N];
int sum[N][N];
int get(int x1, int y1, int x2, int y2) {
  int res = sum[x2][y2];
  if (x1 > 0) res -= sum[x1 - 1][y2];
  if (y1 > 0) res -= sum[x2][y1 - 1];
  if (x1 > 0 && y1 > 0) res += sum[x1 - 1][y1 - 1];
  return res;
}
int n, m, cantx;
bool valid(int x, int y, int lenx, int leny) {
  int have = cantx - get(x, y, x + lenx - 1, y + leny - 1);
  while (1) {
    if (get(x, y, x + lenx - 1, y + leny - 1) != lenx * leny) return 0;
    if (have == 0) return 1;
    if (y + leny < m && tab[x][y + leny] == 'X') {
      have -= get(x, y + leny, x + lenx - 1, y + leny);
      y++;
    } else if (x + lenx < n && tab[x + lenx][y] == 'X') {
      have -= get(x + lenx, y, x + lenx, y + leny - 1);
      x++;
    } else
      break;
  }
  return have == 0;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", &tab[i]);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      sum[i][j] = tab[i][j] == 'X';
      cantx += sum[i][j];
      if (i > 0) sum[i][j] += sum[i - 1][j];
      if (j > 0) sum[i][j] += sum[i][j - 1];
      if (i > 0 && j > 0) sum[i][j] -= sum[i - 1][j - 1];
    }
  bool found = 0;
  int res = -1;
  for (int i = 0; i < n && !found; ++i)
    for (int j = 0; j < m && !found; ++j) {
      if (tab[i][j] == '.') continue;
      int k;
      for (k = i; k < n && tab[k][j] == 'X'; k++)
        ;
      int rows = k;
      for (k = j; k < m && tab[i][k] == 'X'; ++k)
        ;
      int colums = k;
      for (int f = i; f < rows; ++f)
        if (valid(i, j, f - i + 1, colums - j))
          if (res == -1 || (f - i + 1) * (colums - j) < res)
            res = (f - i + 1) * (colums - j);
      for (int f = j; f < colums; ++f)
        if (valid(i, j, rows - i, f - j + 1))
          if (res == -1 || (rows - i) * (f - j + 1) < res)
            res = (rows - i) * (f - j + 1);
      found = 1;
    }
  cout << res << endl;
  return 0;
}
