#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  vector<vector<int> > board;
  int n, m, total;
  vector<int> cF, cL, rF, rL;
  void solve() {
    cin >> n >> m;
    board.resize(n);
    total = 0;
    int colMin = m, colMax = -1, rowMin = n, rowMax = -1;
    for (int row = 0; row < n; ++row) {
      string line;
      cin >> line;
      board[row].resize(m, 0);
      for (int col = 0; col < m; ++col) {
        if (line[col] == 'X') {
          total += 1;
          board[row][col] = 1;
          rowMin = min(rowMin, row);
          rowMax = max(rowMax, row);
          colMin = min(colMin, col);
          colMax = max(colMax, col);
        }
      }
    }
    for (int row = 0; row <= (rowMax - rowMin); ++row) {
      for (int col = 0; col <= (colMax - colMin); ++col) {
        board[row][col] = board[row + rowMin][col + colMin];
      }
      board[row].resize(colMax - colMin + 1);
    }
    board.resize(rowMax - rowMin + 1);
    n = rowMax - rowMin + 1;
    m = colMax - colMin + 1;
    cF.resize(n, -1);
    cL.resize(n, -1);
    rF.resize(m, -1);
    rL.resize(m, -1);
    for (int col = 0; col < m; ++col) {
      bool closed = false;
      for (int row = 0; row < n; ++row) {
        if (board[row][col] > 0) {
          if (closed) {
            cout << -1;
            return;
          }
          if (rF[col] < 0) {
            rF[col] = row;
          }
          rL[col] = row + 1;
        } else {
          if (rF[col] >= 0) {
            closed = true;
          }
        }
      }
      if (rF[col] < 0) {
        cout << -1;
        return;
      }
      if (col == 0) {
        continue;
      }
      if (rF[col] < rF[col - 1] || rL[col] < rL[col - 1]) {
        cout << -1;
        return;
      }
      if (rF[col] >= rL[col - 1]) {
        cout << -1;
        return;
      }
    }
    for (int row = 0; row < n; ++row) {
      for (int col = 0; col < m; ++col) {
        if (board[row][col] > 0) {
          if (cF[row] < 0) {
            cF[row] = col;
          }
          cL[row] = col + 1;
        }
      }
    }
    if (total == n * m) {
      cout << min(n, m);
      return;
    }
    int s = m * n + 1;
    bool ok = true;
    int H = -rF[1] + rL[0];
    for (int col = 2; col < m; ++col) {
      if (-rF[col] + rL[col - 1] != H) {
        ok = false;
        break;
      }
    }
    if (ok) {
      s = min(s, H);
    }
    int W = cL[0] - cF[1];
    ok = true;
    for (int row = 2; row < n; ++row) {
      if (cL[row - 1] - cF[row] != W) {
        ok = false;
        break;
      }
    }
    if (ok) {
      s = min(s, W);
    }
    if (s < m * n) {
      cout << s;
      return;
    }
    H = rL[0] - rF[0];
    if (H < n) {
      W = cL[0] - cF[rL[0]];
      if (check(H, W)) {
        s = min(s, H * W);
      }
    }
    W = cL[0] - cF[0];
    if (W < m) {
      H = rL[0] - rF[cL[0]];
      if (check(H, W)) {
        s = min(s, H * W);
      }
    }
    if (s < m * n) {
      cout << s;
      return;
    }
    cout << -1;
  }
  bool check(int h, int w) {
    int y = 0, x = w;
    int collect = h * w;
    while (y + h - 1 < n) {
      if (x < cL[y]) {
        collect += h * (cL[y] - x);
        x = cL[y];
      } else {
        collect += w;
        y += 1;
      }
    }
    collect -= w;
    return collect == total;
  }
};
int main() {
  Solution solution;
  solution.solve();
  return 0;
}
