#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int ST = 100010;
const int ST1 = 1000010;
const long long MOD = 1000000007;
long long ABS(long long a) {
  if (a < 0)
    return a * (-1);
  else
    return a;
}
int r[1010][1010];
int u[1010][1010];
int d[1010][1010];
int l[1010][1010];
int mas[1010][1010];
int f[1010][1010];
int n, m;
bool check(int sx, int sy, int x, int y) {
  for (int i = sx - x + 1; i <= sx; i++) {
    for (int j = sy - y + 1; j <= sy; j++) {
      if (mas[i][j] == 0) return false;
    }
  }
  return true;
}
bool paint(int x, int y) {
  int sx = -1, sy = -1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      if (mas[i][j] == 1 && sx == -1 && sy == -1) {
        sx = i;
        sy = j;
      }
      f[i][j] = 0;
    }
  bool was = true;
  sx += (x - 1);
  sy += (y - 1);
  pair<int, int> l1 = make_pair(-1, -1), l2 = make_pair(-1, -1);
  while (was) {
    was = false;
    for (; mas[sx][sy] == 1 && check(sx, sy, x, y); sx++) {
      if (make_pair(sx, sy) != l1) was = true;
      l1 = make_pair(sx, sy);
      for (int i = sx - x + 1; i <= sx; i++) {
        for (int j = sy - y + 1; j <= sy; j++) {
          f[i][j] = 1;
          if (mas[i][j] == 0) return false;
        }
      }
    }
    sx--;
    for (; mas[sx][sy] == 1 && check(sx, sy, x, y); sy++) {
      if (make_pair(sx, sy) != l2) was = true;
      l2 = make_pair(sx, sy);
      for (int i = sx - x + 1; i <= sx; i++) {
        for (int j = sy - y + 1; j <= sy; j++) {
          f[i][j] = 1;
          if (mas[i][j] == 0) return false;
        }
      }
    }
    sy--;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (f[i][j] != mas[i][j]) return false;
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string a;
    cin >> a;
    for (int j = 0; j < m; j++) {
      if (a[j] == 'X') mas[i][j] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    int s = 0;
    for (int j = m - 1; j >= 0; j--) {
      r[i][j] = s;
      if (mas[i][j] == 1) {
        s++;
      } else
        s = 0;
    }
    s = 0;
    for (int j = 0; j < m; j++) {
      l[i][j] = s;
      if (mas[i][j] == 1)
        s++;
      else
        s = 0;
    }
  }
  for (int i = 0; i < m; i++) {
    int s = 0;
    for (int j = 0; j < n; j++) {
      u[j][i] = s;
      if (mas[j][i] == 1)
        s++;
      else
        s = 0;
    }
    s = 0;
    for (int j = n - 1; j >= 0; j--) {
      d[j][i] = s;
      if (mas[j][i] == 1)
        s++;
      else
        s = 0;
    }
  }
  int d1x = 1, d1y = 1, d2x = 1, d2y = 1;
  bool nb = true;
  for (int i = 0; i < n && nb; i++)
    for (int j = 0; j < m && nb; j++)
      if (mas[i][j] == 1) {
        d1x = d[i][j] + 1;
        d2y = r[i][j] + 1;
        int i1 = i + d1x - 1;
        int j1 = j + d2y;
        d2x = u[i1][j1] + 1;
        j1 = j + d2y - 1;
        i1 = i + d1x;
        d1y = l[i1][j1] + 1;
        nb = false;
      }
  int ans = INF;
  if (paint(d1x, d1y)) ans = min(d1x * d1y, ans);
  if (paint(d2x, d2y)) ans = min(d2x * d2y, ans);
  if (paint(d1x, 1)) ans = min(d1x, ans);
  if (paint(d2x, 1)) ans = min(d2x, ans);
  if (paint(1, d1y)) ans = min(d1y, ans);
  if (paint(1, d2y)) ans = min(d2y, ans);
  if (paint(1, 1)) ans = 1;
  if (ans == INF)
    cout << -1;
  else
    cout << ans;
  return 0;
}
