#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 20;
int n, m;
char M[N][N];
int rt[N][N];
int down[N][N];
bool vis[N][N];
int ans;
int p, q;
void dfs(int x, int y, int l, int r, int dir, bool ok, int MX) {
  if (dir == 1) {
    for (int i = x; i < x + l; i++) vis[i][y + r - 1] = 1;
  } else {
    for (int i = y; i < y + r; i++) vis[x + l - 1][i] = 1;
  }
  p = l;
  q = r;
  if (dir == 1) {
    if (!ok) {
      if (rt[x + l][y] >= 1) {
        ok = 1;
        r = rt[x][y];
        for (int i = x; i < x + l; i++) {
          for (int j = y; j < y + r; j++) {
            vis[i][j] = 1;
          }
        }
        dfs(x + 1, y, l, r, 1 - dir, ok, MX);
      } else {
        if (down[x][y + r] >= l) dfs(x, y + 1, l, r, dir, ok, MX);
      }
    } else if (down[x][y + r] >= l)
      dfs(x, y + 1, l, r, dir, ok, MX);
    else if (rt[x + l][y] >= r)
      dfs(x + 1, y, l, r, 1 - dir, ok, MX);
  } else {
    if (!ok) {
      if (down[x][y + r] >= 1) {
        ok = 1;
        l = down[x][y];
        for (int i = x; i < x + l; i++) {
          for (int j = y; j < y + r; j++) {
            vis[i][j] = 1;
          }
        }
        dfs(x, y + 1, l, r, 1 - dir, ok, MX);
      } else {
        if (rt[x + l][y] >= r) dfs(x + 1, y, l, r, dir, ok, MX);
      }
    } else if (rt[x + l][y] >= r)
      dfs(x + 1, y, l, r, dir, ok, MX);
    else if (down[x][y + r] >= l)
      dfs(x, y + 1, l, r, 1 - dir, ok, MX);
  }
}
void out() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cout << vis[i][j] << " ";
    }
    cout << endl;
  }
}
bool gao() {
  bool ok = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (!vis[i][j] && M[i][j] == 'X') return 0;
      if (vis[i][j] && M[i][j] != 'X') return 0;
    }
  }
  if (!ok) return 0;
  return 1;
}
int solve() {
  memset(rt, 0, sizeof(rt));
  memset(down, 0, sizeof(down));
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      if (M[i][j] == 'X') {
        rt[i][j] = rt[i][j + 1] + 1;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = n; j >= 1; j--) {
      if (M[j][i] == 'X') {
        down[j][i] = down[j + 1][i] + 1;
      }
    }
  }
  ans = 0x3f3f3f3f;
  bool fid = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (M[i][j] == 'X') {
        memset(vis, 0, sizeof(vis));
        dfs(i, j, down[i][j], 1, 1, 0, rt[i][j]);
        if (gao()) {
          ans = min(ans, p * q);
        }
        memset(vis, 0, sizeof(vis));
        dfs(i, j, 1, rt[i][j], 0, 0, down[i][j]);
        if (gao()) {
          ans = min(ans, p * q);
        }
        fid = 1;
      }
      if (fid) break;
    }
    if (fid) break;
  }
  if (ans == 0x3f3f3f3f)
    return -1;
  else
    return ans;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    memset(vis, 0, sizeof(vis));
    bool ok = 0;
    for (int i = 0; i <= n + 1; i++) {
      for (int j = 0; j <= m + 1; j++) {
        M[i][j] = '.';
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        scanf(" %c", &M[i][j]);
        if (M[i][j] == 'X') {
          ok = 1;
        }
      }
    }
    printf("%d\n", solve());
  }
  return 0;
}
