#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1 << 30;
const int mod = int(1e9) + 7;
const int base = 257;
const int maxn = 2005;
int n, m, d[maxn][maxn], ans = -1, sx = -1, sy = -1;
char c[maxn][maxn];
int get(int xa, int ya, int xb, int yb) {
  int res = d[xb][yb];
  res -= d[xa - 1][yb];
  res -= d[xb][ya - 1];
  res += d[xa - 1][ya - 1];
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
      d[i][j] = d[i][j - 1] + (c[i][j] == 'X');
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (c[i][j] == 'X' && sx == -1) sx = i, sy = j;
      d[i][j] += d[i - 1][j];
    }
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++) {
      if (get(sx, sy, sx + x - 1, sy + y - 1) == x * y) {
        int sxx = sx, syy = sy;
        vector<pair<int, int> > v;
        v.push_back(make_pair(sxx, syy));
      go:;
        int sum1 = get(sxx + 1, syy, sxx + 1 + x - 1, syy + y - 1);
        int sum2 = get(sxx, syy + 1, sxx + x - 1, syy + 1 + y - 1);
        if (sum1 == x * y && sum2 == x * y) continue;
        if (sum1 == x * y) {
          sxx++;
          v.push_back(make_pair(sxx, syy));
          goto go;
        } else if (sum2 == x * y) {
          syy++;
          v.push_back(make_pair(sxx, syy));
          goto go;
        } else {
          int tot = 1ll * get(v[0].first, v[0].second, v[0].first + x - 1,
                              v[0].second + y - 1);
          for (int i = 1; i < v.size(); i++) {
            tot += get(v[i].first, v[i].second, v[i].first + x - 1,
                       v[i].second + y - 1);
            tot -= get(v[i].first, v[i].second, v[i - 1].first + x - 1,
                       v[i - 1].second + y - 1);
          }
          if (d[n][m] == tot) {
            if (ans == -1)
              ans = x * y;
            else
              ans = min(ans, x * y);
          } else
            continue;
        }
      }
    }
  cout << ans;
  return 0;
}
