#include <bits/stdc++.h>
using namespace std;
int ri() {
  static int res;
  scanf("%d", &res);
  return res;
}
int numbits(int n) { return n ? 1 + numbits(n & (n - 1)) : 0; }
class timer {
 public:
  timer() : t_(clock()) {}
  void restart() { t_ = clock(); }
  float elapsed() { return float(clock() - t_) / CLOCKS_PER_SEC; }

 private:
  clock_t t_;
};
void run();
int main() {
  run();
  return 0;
}
int check(int r, int c, int h, int w, const vector<string>& vs) {
  int area = h * w;
  for (int i = r; i < r + h; ++i) {
    if (vs[i][c] != 'X' || vs[i][c + w - 1] != 'X') {
      return 0;
    }
  }
  while (true) {
    if (r + h < vs.size() && vs[r + h][c] == 'X' &&
        vs[r + h][c + w - 1] == 'X') {
      ++r;
      area += w;
      continue;
    }
    if (c + w < vs[0].size() && vs[r][c + w] == 'X' &&
        vs[r + h - 1][c + w] == 'X') {
      ++c;
      area += h;
      continue;
    }
    break;
  }
  return area;
}
void run() {
  int n, m;
  cin >> n >> m;
  vector<string> b(n);
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  int cnt = 0;
  int pf = 0, pl = 0;
  for (int i = 0; i < n; ++i) {
    int tot = count((b[i]).begin(), (b[i]).end(), 'X');
    if (!tot) {
      if (cnt) {
        for (int j = i + 1; j < n; ++j) {
          if (count((b[j]).begin(), (b[j]).end(), 'X')) {
            std::cout << "-1" << endl;
            return;
          }
        }
      } else {
        continue;
      }
    } else {
      int f = -1, l = -1;
      for (int j = 0; j < m; ++j) {
        if (b[i][j] == 'X') {
          if (f == -1) {
            f = j;
          }
          l = j;
        }
      }
      if (l - f + 1 != tot) {
        std::cout << "-1" << endl;
        return;
      }
      if (pf > f || pl > l) {
        std::cout << "-1" << endl;
        return;
      }
      pf = f;
      pl = l;
      ++cnt;
    }
  }
  int r = -1, c = -1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (r == -1 && c == -1 && b[i][j] == 'X') {
        r = i;
        c = j;
      }
    }
  }
  int w = 0, h = 0;
  for (int i = c; i < m; ++i) {
    if (b[r][i] == 'X') {
      ++w;
    }
  }
  for (int i = r; i < n; ++i) {
    if (b[i][c] == 'X') {
      ++h;
    }
  }
  int mn = 1000000000;
  int area = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (b[i][j] == 'X') {
        ++area;
      }
    }
  }
  for (int i = 1; i <= w; ++i) {
    if (check(r, c, h, i, b) == area) {
      mn = min(mn, h * i);
    }
  }
  for (int i = 1; i <= h; ++i) {
    if (check(r, c, i, w, b) == area) {
      mn = min(mn, i * w);
    }
  }
  if (mn <= 1000000) {
    cout << mn << endl;
  } else {
    cout << "-1" << endl;
  }
}
