#include <bits/stdc++.h>
const int maxn = 1005;
int n, m, ptr, ans;
char mp[maxn][maxn];
struct point {
  int x, y;
} st, brush;
bool vis[maxn][maxn];
bool check() {
  point now = st;
  int cnt = 0, i, j;
  while (now.x + brush.x - 1 < n && now.y + brush.y - 1 < m) {
    if (now.y + brush.y < m && mp[now.x][now.y + brush.y] == 'X') {
      for (i = 0; i < brush.x; i++)
        if (mp[now.x + i][now.y + brush.y] == 'X')
          cnt++;
        else
          return false;
      now.y++;
    } else if (now.x + brush.x < n && mp[now.x + brush.x][now.y] == 'X') {
      for (j = 0; j < brush.y; j++)
        if (mp[now.x + brush.x][now.y + j] == 'X')
          cnt++;
        else
          return false;
      now.x++;
    } else
      break;
  }
  return cnt + brush.x * brush.y == ptr;
}
int main() {
  int i, j;
  while (~scanf("%d%d", &n, &m)) {
    bool ok = 1;
    for (i = 0; i < n; i++) scanf("%s", mp[i]);
    st.x = -1;
    ptr = 0;
    for (i = 0; i < n; i++)
      for (j = 0; j < m; j++)
        if (mp[i][j] == 'X') {
          ptr++;
          if (st.x == -1)
            st.x = i, st.y = j;
          else if (i < st.x || j < st.y)
            ok = 0;
        }
    ans = -1;
    if (ok) {
      int lrmax = 0, udmax = 0;
      for (i = st.x; i < n && mp[i][st.y] == 'X'; i++) udmax++;
      for (j = st.y; j < m && mp[st.x][j] == 'X'; j++) lrmax++;
      brush.y = lrmax;
      for (brush.x = 1;
           brush.x <= udmax && (ans == -1 || brush.x * brush.y < ans);
           brush.x++) {
        bool brush_ok = 1;
        for (j = 0; j < brush.y; j++)
          if (mp[st.x + brush.x - 1][st.y + j] != 'X') brush_ok = 0;
        if (!brush_ok) break;
        if (check())
          if (ans == -1 || brush.x * brush.y < ans) ans = brush.x * brush.y;
      }
      brush.x = udmax;
      for (brush.y = 1;
           brush.y <= lrmax && (ans == -1 || brush.x * brush.y < ans);
           brush.y++) {
        bool brush_ok = 1;
        for (i = 0; i < brush.x; i++)
          if (mp[st.x + i][st.y + brush.y - 1] != 'X') brush_ok = 0;
        if (!brush_ok) break;
        if (check())
          if (ans == -1 || brush.x * brush.y < ans) ans = brush.x * brush.y;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
