#include <bits/stdc++.h>
using namespace std;
char arr[1111][1111];
int n, m;
int sx, sy;
bool flood_fill() {
  queue<int> Q;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (arr[i][j] == 'X') {
        Q.push(i);
        Q.push(j);
        arr[i][j] = 'x';
        goto out;
      }
    }
  }
out:
  if (Q.size() == 0) return false;
  const int helper[][2] = {
      {1, 0},
      {-1, 0},
      {0, 1},
      {0, -1},
  };
  while (Q.size()) {
    int x = Q.front();
    Q.pop();
    int y = Q.front();
    Q.pop();
    for (const auto &d : helper) {
      int nx = x + d[0];
      int ny = y + d[1];
      if (arr[nx][ny] == 'X') {
        arr[nx][ny] = 'x';
        Q.push(nx);
        Q.push(ny);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (arr[i][j] == 'X') {
        return false;
      }
    }
  }
  return true;
}
bool check_pattern() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (arr[i][j] == 'x' && arr[i + 1][j] == 'x' && arr[i][j + 1] == 'x' &&
          arr[i + 1][j + 1] != 'x') {
        return false;
      }
      if (arr[i][j] == 'x' && arr[i - 1][j] == 'x' && arr[i][j - 1] == 'x' &&
          arr[i - 1][j - 1] != 'x') {
        return false;
      }
    }
  }
}
bool check(int w, int h) {
  int x = sx;
  int y = sy;
  const int helper[][2] = {
      {0, 0},
      {h - 1, 0},
      {0, w - 1},
      {h - 1, w - 1},
  };
  int dx = -1;
  int dy = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (arr[i][j] == 'x') {
        dx = i;
        dy = j;
      }
    }
  }
  while (true) {
    bool can_go_right = arr[x][y + w] == 'x';
    bool can_go_down = arr[x + h][y] == 'x';
    for (const auto &d : helper) {
      if (arr[x + d[0]][y + d[1]] != 'x') return false;
    }
    if (can_go_right && can_go_down) return false;
    if (!can_go_right && !can_go_down) {
      if (x + h - 1 == dx && y + w - 1 == dy) return true;
    }
    x = can_go_down ? x + 1 : x;
    y = can_go_down ? y : y + 1;
  }
  return false;
}
void guess() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (arr[i][j] == 'x') {
        sx = i;
        sy = j;
        goto out2;
      }
    }
  }
out2:
  int x1 = -1, x2 = -1, y1 = -1, y2 = -1;
  for (int i = sx;; i++) {
    if (arr[i][sy] == 'x' && arr[i + 1][sy] != 'x') {
      x1 = i;
      y1 = sy;
      break;
    }
  }
  for (int i = sy;; i++) {
    if (arr[sx][i] == 'x' && arr[sx][i + 1] != 'x') {
      x2 = sx;
      y2 = i;
      break;
    }
  }
  int ans = 2000000;
  for (int i = sx; i <= x1; i++) {
    for (int j = sy; j <= y2; j++) {
      if (arr[i][j] == 'x' && arr[i][j + 1] == 'x' &&
          arr[i + 1][j + 1] == 'x' && arr[i + 1][j] != 'x') {
        int h = i - sx + 1;
        int w = y2 - j;
        if (check(w, h)) {
          ans = min(ans, w * h);
        }
      }
      if (arr[i][j] == 'x' && arr[i + 1][j] == 'x' &&
          arr[i + 1][j + 1] == 'x' && arr[i][j + 1] != 'x') {
        int h = x1 - i;
        int w = j - sy + 1;
        if (check(w, h)) {
          ans = min(ans, w * h);
        }
      }
    }
  }
  if (ans == 2000000) {
    if (y2 - sy > x1 - sx) {
      int h = x1 - sx + 1;
      int w = 1;
      if (check(w, h)) {
        ans = min(ans, w * h);
      }
    } else {
      int h = 1;
      int w = y2 - sy + 1;
      if (check(w, h)) {
        ans = min(ans, w * h);
      }
    }
  }
  if (ans == 2000000) ans = -1;
  cout << ans << endl;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", &arr[i][1]);
  }
  if (!flood_fill() || !check_pattern()) {
    cout << -1 << endl;
  } else {
    guess();
  }
  return 0;
}
