#include <bits/stdc++.h>
using namespace std;
const long long INF64 = ((long long)1E18);
const int INF = 1E9 + 7;
template <class C>
void mini(C& a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
  a4 = max(a4, b4);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
  out << "(" << pair.first << ", " << pair.second << ")";
  return out;
}
int h, w, best = -1, sx = -1, sy = -1, ex, ey;
int co[1005][1005], sum[1005][1005];
int get_sum(int lx, int ly, int rx, int ry) {
  return sum[rx][ry] + sum[lx - 1][ly - 1] - sum[rx][ly - 1] - sum[lx - 1][ry];
}
void doit(int hh, int ww) {
  int x, y, pole = hh * ww;
  x = sx, y = sy;
  while (x + hh - 1 <= h && y + ww - 1 <= w) {
    {
      if (0)
        cerr << "x"
             << " = " << x << ", "
             << "y"
             << " = " << y << endl;
    };
    {
      if (0)
        cerr << "x"
             << " = " << x << ", "
             << "y"
             << " = " << y << ", "
             << "x + hh - 1"
             << " = " << x + hh - 1 << ", "
             << "y + ww - 1"
             << " = " << y + ww - 1 << endl;
    };
    if (get_sum(x, y, x + hh - 1, y + ww - 1) != pole) return;
    bool a = co[x + hh][y];
    bool b = co[x][y + ww];
    {
      if (0)
        cerr << "a"
             << " = " << a << ", "
             << "b"
             << " = " << b << endl;
    };
    if (a && b) return;
    if (!a && !b) break;
    if (a) ++x;
    if (b) ++y;
  }
  if (x + hh - 1 != ex || y + ww - 1 != ey) return;
  mini(best, pole);
}
void dupa() {
  cout << -1 << endl;
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> h >> w;
  best = INF;
  for (int i = (1); i <= (h); ++i)
    for (int j = (1); j <= (w); ++j) {
      char c;
      cin >> c;
      if (c == 'X') {
        co[i][j] = 1;
        if (sx == -1) {
          sx = i;
          sy = j;
        }
        ex = i;
        ey = j;
      } else
        co[i][j] = 0;
    }
  vector<pair<int, int> > t;
  for (int i = (1); i <= (h); ++i) {
    int lewy = -1, prawy, ile = 0;
    for (int j = (1); j <= (w); ++j)
      if (co[i][j]) {
        ++ile;
        prawy = j;
        if (lewy == -1) lewy = j;
      }
    if (lewy == -1) {
      if (t.empty())
        continue;
      else
        t.push_back(make_pair(-1, -1));
      continue;
    }
    if (prawy - lewy + 1 != ile) dupa();
    if (t.empty()) {
      t.push_back(make_pair(lewy, prawy));
      continue;
    } else {
      pair<int, int> p = t.back();
      if (p.first == -1) dupa();
      if (!(lewy >= p.first && prawy >= p.second)) dupa();
      t.push_back(make_pair(lewy, prawy));
    }
  }
  for (int i = (1); i <= (h); ++i) {
    int acsum = 0;
    for (int j = (1); j <= (w); ++j) {
      acsum += co[i][j];
      sum[i][j] = sum[i - 1][j] + acsum;
    }
  }
  int hh, ww;
  for (int j = (0); j <= (w); ++j)
    if (co[sx][sy + j])
      ww = j + 1;
    else
      break;
  for (int j = (0); j <= (h); ++j)
    if (co[sx + j][sy])
      hh = j + 1;
    else
      break;
  for (int j = (1); j <= (hh); ++j) doit(j, ww);
  for (int j = (1); j <= (ww); ++j) doit(hh, j);
  if (sx == -1) best = 0;
  if (best == INF) best = -1;
  cout << best << endl;
  return 0;
}
