#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
long long INFLL = 1000000000000000000LL;
int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int my[8] = {0, 0, -1, 1, -1, 1, -1, 1};
char x[1005][1005];
int hor[1005][1005];
int ch[1005][1005];
int ver[1005][1005];
int cv[1005][1005];
int num[1005][1005];
void FAIL() {
  puts("-1");
  exit(0);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int(a) = (0); (a) <= (n); (a)++) {
    gets(x[a] + 1);
  }
  pair<int, int> pos = make_pair(-1, -1);
  pair<int, int> pos2 = make_pair(-1, -1);
  for (int(a) = (1); (a) <= (n); (a)++) {
    for (int(b) = (1); (b) <= (m); (b)++) {
      if (x[a][b] == 'X') {
        pos = make_pair(a, b);
        break;
      }
    }
    if (pos != make_pair(-1, -1)) break;
  }
  pos2 = pos;
  for (int(a) = (1); (a) <= (n); (a)++) {
    for (int(b) = (m); (b) >= (1); (b)--) {
      if (x[a][b] != 'X')
        hor[a][b] = 0;
      else
        hor[a][b] = hor[a][b + 1] + 1;
      ch[a][b] = ch[a][b + 1] + (x[a][b] == 'X');
    }
  }
  for (int(a) = (1); (a) <= (m); (a)++) {
    for (int(b) = (n); (b) >= (1); (b)--) {
      if (x[b][a] != 'X')
        ver[b][a] = 0;
      else
        ver[b][a] = ver[b + 1][a] + 1;
      cv[b][a] = cv[b + 1][a] + (x[b][a] == 'X');
    }
  }
  for (int(a) = (n); (a) >= (1); (a)--) {
    for (int(b) = (m); (b) >= (1); (b)--) {
      num[a][b] =
          num[a + 1][b] + num[a][b + 1] - num[a + 1][b + 1] + (x[a][b] == 'X');
    }
  }
  if (num[pos.first][pos.second] != num[1][1])
    FAIL();
  else {
    int ans = INF;
    if (1) {
      int ssh = hor[pos.first][pos.second];
      int ssv = 1;
      bool fixed = 0;
      bool failed = 0;
      while (1) {
        if (hor[pos.first][pos.second] != ch[pos.first][pos.second]) {
          failed = 1;
          break;
        }
        if (ver[pos.first][pos.second] != cv[pos.first][pos.second]) {
          failed = 1;
          break;
        }
        int valh = hor[pos.first][pos.second];
        int valv = ver[pos.first][pos.second];
        if (valv == 1) {
          fixed = 1;
        }
        if (fixed) {
          if (valh > ssh && valv == ssv) {
            pos.second++;
          } else if (valv > ssv && valh == ssh) {
            pos.first++;
          } else if (valv == ssv && valh == ssh) {
            bool valid = 1;
            for (int(b) = (pos.first); (b) <= (n); (b)++) {
              for (int(c) = (pos.second); (c) <= (m); (c)++) {
                if (b - pos.first + 1 <= ssv && c - pos.second + 1 <= ssh)
                  valid &= (x[b][c] == 'X');
                else {
                  valid &= (x[b][c] != 'X');
                }
              }
            }
            if (!valid) {
              failed = 1;
              break;
            } else {
              (ans) = min((ans), (ssh * ssv));
              break;
            }
          } else {
            failed = 1;
            break;
          }
        } else {
          if (valh == ssh) {
            pos.first++;
          } else {
            ssv = valv;
            fixed = 1;
            pos.second++;
          }
        }
      }
    }
    if (1) {
      pos = pos2;
      int ssh = 1;
      int ssv = ver[pos.first][pos.second];
      bool fixed = 0;
      bool failed = 0;
      while (1) {
        if (hor[pos.first][pos.second] != ch[pos.first][pos.second]) {
          failed = 1;
          break;
        }
        if (ver[pos.first][pos.second] != cv[pos.first][pos.second]) {
          failed = 1;
          break;
        }
        int valh = hor[pos.first][pos.second];
        int valv = ver[pos.first][pos.second];
        if (valh == 1) {
          fixed = 1;
        }
        if (fixed) {
          if (valh > ssh && valv == ssv) {
            pos.second++;
          } else if (valv > ssv && valh == ssh) {
            pos.first++;
          } else if (valv == ssv && valh == ssh) {
            bool valid = 1;
            for (int(b) = (pos.first); (b) <= (n); (b)++) {
              for (int(c) = (pos.second); (c) <= (m); (c)++) {
                if (b - pos.first + 1 <= ssv && c - pos.second + 1 <= ssh)
                  valid &= (x[b][c] == 'X');
                else
                  valid &= (x[b][c] != 'X');
              }
            }
            if (!valid) {
              failed = 1;
              break;
            } else {
              (ans) = min((ans), (ssh * ssv));
              break;
            }
          } else {
            failed = 1;
            break;
          }
        } else {
          if (valv == ssv) {
            pos.second++;
          } else {
            ssh = valh;
            fixed = 1;
            pos.first++;
          }
        }
      }
    }
    if (ans == INF) ans = -1;
    cout << ans << endl;
  }
}
