#include <bits/stdc++.h>
using namespace std;
string s;
int a[1005][1005];
int num[1005][1005];
int n, m;
inline int all(int x1, int y1, int x2, int y2) {
  return num[x2][y2] - num[x2][y1 - 1] - num[x1 - 1][y2] +
             num[x1 - 1][y1 - 1] ==
         (x2 - x1 + 1) * (y2 - y1 + 1);
}
int bs1(int x1, int x2, int y, int d) {
  int l = y, r = m - d + 2;
  while (l < r - 1) {
    int mid = (l + r) >> 1;
    if (all(x1, y, x2, mid + d - 1))
      l = mid;
    else
      r = mid;
  }
  return l;
}
int bs2(int y1, int y2, int x, int d) {
  int l = x, r = n - d + 2;
  while (l < r - 1) {
    int mid = (l + r) >> 1;
    if (all(x, y1, mid + d - 1, y2))
      l = mid;
    else
      r = mid;
  }
  return l;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  while (cin >> n >> m) {
    memset(num, 0, sizeof(num));
    int x = -1, y = -1;
    int ret = 0;
    for (int i = (1); i <= (n); i++) {
      cin >> s;
      for (int j = (1); j <= (m); j++) {
        if (s[j - 1] == 'X') {
          a[i][j] = 1;
          ret++;
        } else
          a[i][j] = 0;
      }
    }
    for (int i = (1); i <= (n); i++) {
      for (int j = (1); j <= (m); j++) {
        if (x == -1 && a[i][j] == 1) x = i, y = j;
        num[i][j] = num[i - 1][j] + num[i][j - 1] - num[i - 1][j - 1] + a[i][j];
      }
    }
    if (ret == 0) {
      cout << 0 << endl;
      continue;
    }
    int l1, l2;
    int i;
    for (i = x; a[i][y] == 1; i++) {
    }
    l1 = i - x;
    for (i = y; a[x][i] == 1; i++) {
    }
    l2 = i - y;
    int ans = 1000000007;
    int f, px, py;
    for (int i = (1); i <= (m); i++) {
      if (!all(x, y, x + l1 - 1, y + i - 1)) break;
      int tot = l1 * i;
      px = x, py = y;
      f = 0;
      while (1) {
        int np;
        int mov = 0;
        if (f == 0) {
          np = bs1(px, px + l1 - 1, py, i);
          if (np != py) mov = 1;
          tot += (np - py) * l1;
          py = np;
          f = 1;
        } else if (f == 1) {
          np = bs2(py, py + i - 1, px, l1);
          if (np != px) mov = 1;
          tot += (np - px) * i;
          px = np;
          f = 0;
        }
        if (!mov) break;
      }
      if (tot == ret) {
        ans = min(ans, l1 * i);
        break;
      }
    }
    for (int i = (1); i <= (n); i++) {
      if (!all(x, y, x + i - 1, y + l2 - 1)) break;
      int tot = l2 * i;
      px = x, py = y;
      f = 0;
      while (1) {
        int np;
        int mov = 0;
        if (f == 0) {
          np = bs2(py, py + l2 - 1, px, i);
          if (np != px) mov = 1;
          tot += (np - px) * l2;
          px = np;
          f = 1;
        } else if (f == 1) {
          np = bs1(px, px + i - 1, py, l2);
          if (np != py) mov = 1;
          tot += (np - py) * i;
          py = np;
          f = 0;
        }
        if (!mov) break;
      }
      if (tot == ret) {
        ans = min(ans, l2 * i);
        break;
      }
    }
    if (ans == 1000000007)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
