#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j, ada, jum, p[2010][2010], has, D[2010][2010], itung, X, Y,
    dx[4] = {0, 0, -1, 1}, dy[4] = {-1, 1, 0, 0};
char ct;
pair<long long, long long> awal;
vector<pair<long long, pair<long long, long long> > > v;
long long jumlah(long long aa, long long bb, long long cc, long long dd) {
  return p[cc][dd] - p[aa - 1][dd] - p[cc][bb - 1] + p[aa - 1][bb - 1];
}
void dfs(long long aa, long long bb) {
  queue<pair<long long, long long> > q;
  q.push(make_pair(aa, bb));
  long long oi = 0;
  while (!q.empty() && oi <= 10000000) {
    oi++;
    long long xx = q.front().first, yy = q.front().second;
    q.pop();
    if (D[xx][yy] == 0 || xx <= 0 || yy <= 0 || xx > n || yy > m) continue;
    D[xx][yy] = 0;
    itung++;
    long long ii;
    for (ii = 0; ii < 4; ii++) q.push(make_pair(xx + dx[ii], yy + dy[ii]));
  }
}
void cek(long long aa, long long bb, long long cc) {
  if (aa > n || bb > m) return;
  if (cc + jumlah(aa, bb, n, m) != jum ||
      jumlah(aa, bb, aa + X - 1, bb + Y - 1) != X * Y)
    return;
  if (jumlah(aa, bb, n, m) == X * Y) {
    has = X * Y;
    return;
  }
  cek(aa + 1, bb, cc + Y);
  cek(aa, bb + 1, cc + X);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      cin >> ct;
      ada = 0;
      if (ct == 'X') {
        D[i][j] = 1;
        if (awal == make_pair(0LL, 0LL)) awal = make_pair(i, j);
        jum++;
        ada = 1;
      }
      p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1] + ada;
      v.push_back(make_pair(i * j, make_pair(i, j)));
    }
  dfs(awal.first, awal.second);
  if (itung < jum) {
    cout << -1 << "\n";
    return 0;
  }
  sort(v.begin(), v.end());
  has = -1;
  for (i = 0; i < v.size(); i++) {
    X = v[i].second.first;
    Y = v[i].second.second;
    if (has != -1) break;
    cek(awal.first, awal.second, 0);
  }
  cout << has << "\n";
}
