#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const int INF = 1000000000;
char mp[N][N];
int mk[N][N], num;
int n, m;
int ch[][2] = {1, 0, -1, 0, 0, 1, 0, -1};
bool range(int x, int y) {
  if (x >= 0 && x < n && y >= 0 && y < m) return true;
  return false;
}
int tol;
void bfs(int x, int y) {
  queue<pair<int, int> > q;
  q.push(make_pair(x, y));
  while (!q.empty()) {
    pair<int, int> t = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int tx = t.first + ch[i][0];
      int ty = t.second + ch[i][1];
      if (range(tx, ty) && mp[tx][ty] == 'X' && mk[tx][ty] == -1) {
        mk[tx][ty] = num;
        q.push(make_pair(tx, ty));
      }
    }
  }
  num++;
}
bool check(int y) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < y; j++)
      if (mp[i][j] == 'X') return false;
  }
  return true;
}
bool calc_down(int x, int y1, int y2) {
  if (range(x, y1)) {
    while (y1 < y2) {
      if (mp[x][y1] == 'X') {
      } else
        return false;
      y1++;
    }
    return true;
  }
  return false;
}
bool calc_right(int y, int x1, int x2) {
  if (range(x1, y)) {
    while (x1 < x2) {
      if (mp[x1][y] == 'X') {
      } else
        return false;
      x1++;
    }
    return true;
  }
  return false;
}
int X, Y;
bool ok;
bool findone(int r, int c) {
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++)
      if (mp[X + i][Y + j] == 'X') {
      } else {
        ok = false;
        return false;
      }
  }
  bool down, right;
  int x = X, y = Y;
  int cnt = r * c;
  while (1) {
    down = calc_down(x + r, y, y + c);
    right = calc_right(y + c, x, x + r);
    if (down && !right)
      x++, cnt += c;
    else if (!down && right)
      y++, cnt += r;
    else if (down && right)
      return false;
    else
      break;
  }
  return cnt == tol;
}
int main() {
  while (scanf("%d%d", &n, &m) + 1) {
    for (int i = 0; i < n; i++) scanf("%s", mp[i]);
    memset(mk, -1, sizeof(mk));
    tol = 0, num = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (mp[i][j] == 'X' && mk[i][j] == -1) bfs(i, j);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) tol += mp[i][j] == 'X';
    if (num != 1) {
      printf("-1\n");
      continue;
    }
    int sx(-1), sy(-1);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++)
        if (mp[i][j] == 'X') {
          sx = i, sy = j;
          break;
        }
      if (sx != -1) break;
    }
    X = sx, Y = sy;
    if (check(sy)) {
      int ans = INF;
      int i = sx, k;
      while (i < n && mp[i][sy] == 'X') i++;
      k = i - sx;
      while (i < n && mp[i][sy] == '.') i++;
      if (i < n) {
        printf("-1\n");
        continue;
      }
      ok = true;
      for (int j = 1; j <= m; j++) {
        if (findone(k, j)) {
          ans = k * j;
          break;
        }
        if (!ok) break;
      }
      i = sy;
      while (i < m && mp[sx][i] == 'X') i++;
      k = i - sy;
      while (i < m && mp[sx][i] == '.') i++;
      if (i < m) {
        printf("-1\n");
        continue;
      }
      ok = true;
      for (int j = 1; j <= n; j++) {
        if (findone(j, k)) {
          ans = min(ans, j * k);
          break;
        }
        if (!ok) break;
      }
      if (ans == INF)
        printf("-1\n");
      else
        printf("%d\n", ans);
    } else {
      printf("-1\n");
    }
  }
  return 0;
}
