#include <bits/stdc++.h>
using namespace std;
int n, m;
string baca[1005];
bool visit[1005][1005];
int xx[] = {0, 0, 1, -1};
int yy[] = {1, -1, 0, 0};
pair<int, int> start, target;
int h[1005][1005], w[1005][1005];
bool valid(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }
void bfs(int x, int y) {
  queue<pair<int, int> > q;
  q.push(make_pair(x, y));
  while (!q.empty()) {
    pair<int, int> now = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int nowx = now.first + xx[i];
      int nowy = now.second + yy[i];
      if (valid(nowx, nowy) && !visit[nowx][nowy] && baca[nowx][nowy] == 'X') {
        visit[nowx][nowy] = true;
        q.push(make_pair(nowx, nowy));
      }
    }
  }
}
void build() {
  memset(visit, false, sizeof(visit));
  int nowx = start.first, nowy = start.second;
  while (valid(nowx, nowy) && baca[nowx][nowy] == 'X') {
    visit[nowx][nowy] = true;
    nowy++;
  }
  nowy = start.second;
  while (valid(nowx, nowy) && baca[nowx][nowy] == 'X') {
    visit[nowx][nowy] = true;
    nowx++;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!visit[i][j]) {
        bool a = false, b = false;
        if (i != 0) a = visit[i - 1][j];
        if (j != 0) b = visit[i][j - 1];
        visit[i][j] = (a && b);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (baca[i][j] != 'X') continue;
      if (i != 0) {
        h[i][j] = h[i - 1][j] + 1;
      } else {
        h[i][j] = 1;
      }
      if (j != 0) {
        w[i][j] = w[i][j - 1] + 1;
      } else {
        w[i][j] = 1;
      }
    }
  }
}
bool bisa(int x, int y, int pan, int leb) {
  if (x == target.first && y == target.second) {
    return true;
  }
  int nowx, nowy;
  int bisa1, bisa2;
  nowx = x;
  nowy = y + 1;
  if (valid(nowx, nowy) && baca[nowx][nowy] == 'X') {
    if (h[nowx][nowy] == pan) {
      bisa1 = 2;
    } else {
      bisa1 = 0;
    }
  } else {
    bisa1 = 1;
  }
  nowx = x + 1;
  nowy = y;
  if (valid(nowx, nowy) && baca[nowx][nowy] == 'X') {
    if (w[nowx][nowy] == leb) {
      bisa2 = 2;
    } else {
      bisa2 = 0;
    }
  } else {
    bisa2 = 1;
  }
  if (bisa1 == 0) {
    if (bisa2 == 2) {
      return bisa(x + 1, y, pan, leb);
    } else {
      return false;
    }
  } else if (bisa1 == 1) {
    if (bisa2 == 2) {
      return bisa(x + 1, y, pan, leb);
    } else {
      return false;
    }
  } else {
    if (bisa2 == 0 || bisa2 == 1) {
      return bisa(x, y + 1, pan, leb);
    } else {
      return false;
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> baca[i];
  }
  memset(visit, false, sizeof(visit));
  int cnt = 0;
  start.first = n;
  start.second = m;
  target.first = -1;
  target.second = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (baca[i][j] == 'X') {
        start.first = min(start.first, i);
        start.second = min(start.second, j);
        target.first = max(target.first, i);
        target.second = max(target.second, j);
      }
      if (baca[i][j] == 'X' && !visit[i][j]) {
        cnt++;
        visit[i][j] = true;
        bfs(i, j);
      }
    }
  }
  if (cnt > 1 || baca[start.first][start.second] != 'X' ||
      baca[target.first][target.second] != 'X') {
    cout << "-1\n";
    return 0;
  }
  build();
  int ans = 1e9;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i * j > ans) continue;
      int nowx = start.first + i - 1;
      int nowy = start.second + j - 1;
      if (valid(nowx, nowy) && !visit[nowx][nowy]) continue;
      bool coba = bisa(nowx, nowy, i, j);
      if (coba) {
        ans = min(ans, i * j);
      }
    }
  }
  if (ans == 1e9) {
    cout << "-1\n";
  } else {
    cout << ans << "\n";
  }
}
