#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const int MAX = 100007;
const int MOD = 1000000007;
const int INF = 1000000000;
char s[1007][1007];
char ss[1007][1007];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = (0); i < (n); ++i) {
    scanf("%s", s[i]);
  }
  int res = INF;
  {
    int x = -1;
    int y = -1;
    for (int i = (0); i < (n); ++i) {
      if (x != -1) break;
      for (int j = (0); j < (m); ++j) {
        if (s[i][j] == 'X') {
          x = i;
          y = j;
          break;
        }
      }
    }
    if (x == -1) {
      cout << 0 << endl;
      return 0;
    }
    int len = 0;
    int xx = x;
    while (xx < n && s[xx][y] == 'X') {
      ++xx;
      ++len;
    }
    vector<pair<int, int> > b;
    bool last = 0;
    for (int i = (x); i < (n); ++i) {
      int l = -1;
      for (int j = (0); j < (m); ++j) {
        if (s[i][j] == 'X') {
          l = j;
          break;
        }
      }
      if (l == -1) {
        if (b.size()) {
          last = 1;
        }
      } else {
        if (last) {
          cout << -1 << endl;
          return 0;
        }
        int r = l;
        while (r < m && s[i][r] == 'X') {
          ++r;
        }
        for (int j = (r); j < (m); ++j) {
          if (s[i][j] == 'X') {
            cout << -1 << endl;
            return 0;
          }
        }
        b.push_back(make_pair(l, r - 1));
      }
    }
    int h;
    bool ok = 1;
    for (int i = (0); i < (len); ++i) {
      if (b[i].first != b[0].first) {
        ok = 0;
      }
      if (b[b.size() - 1 - i].second != b.back().second) {
        ok = 0;
      }
    }
    for (int i = (0); i < (n); ++i) {
      for (int j = (0); j < (m); ++j) {
        ss[i][j] = '.';
      }
    }
    if (ok) {
      int L = b[0].first;
      int R = b[0].second;
      if (b.size() == len) {
        res = min(res, len);
      } else {
        h = -b[len].first + b[0].second + 1;
        if (h >= 1) {
          int xx = x;
          int yy = y;
          for (int ii = (0); ii < (len); ++ii) {
            for (int jj = (0); jj < (h); ++jj) {
              ss[xx + ii][yy + jj] = 'X';
            }
          }
          while (1) {
            if (xx + len < n && s[xx + len][yy] == 'X') {
              for (int jj = (0); jj < (h); ++jj) {
                ss[xx + len][yy + jj] = 'X';
              }
              ++xx;
            } else {
              if (yy + h < m && s[xx][yy + h] == 'X') {
                for (int ii = (0); ii < (len); ++ii) {
                  ss[xx + ii][yy + h] = 'X';
                }
                ++yy;
              } else {
                break;
              }
            }
          }
        }
      }
    }
    bool g = 1;
    for (int i = (0); i < (n); ++i) {
      for (int j = (0); j < (m); ++j) {
        if (s[i][j] != ss[i][j]) {
          g = 0;
        }
      }
    }
    if (g) {
      res = min(res, len * h);
    }
  }
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (m); ++j) {
      ss[j][i] = s[i][j];
    }
  }
  swap(n, m);
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (m); ++j) {
      s[i][j] = ss[i][j];
    }
  }
  {
    int x = -1;
    int y = -1;
    for (int i = (0); i < (n); ++i) {
      if (x != -1) break;
      for (int j = (0); j < (m); ++j) {
        if (s[i][j] == 'X') {
          x = i;
          y = j;
          break;
        }
      }
    }
    if (x == -1) {
      cout << 0 << endl;
      return 0;
    }
    int len = 0;
    int xx = x;
    while (xx < n && s[xx][y] == 'X') {
      ++xx;
      ++len;
    }
    vector<pair<int, int> > b;
    bool last = 0;
    for (int i = (x); i < (n); ++i) {
      int l = -1;
      for (int j = (0); j < (m); ++j) {
        if (s[i][j] == 'X') {
          l = j;
          break;
        }
      }
      if (l == -1) {
        if (b.size()) {
          last = 1;
        }
      } else {
        if (last) {
          cout << -1 << endl;
          return 0;
        }
        int r = l;
        while (r < m && s[i][r] == 'X') {
          ++r;
        }
        for (int j = (r); j < (m); ++j) {
          if (s[i][j] == 'X') {
            cout << -1 << endl;
            return 0;
          }
        }
        b.push_back(make_pair(l, r - 1));
      }
    }
    int h;
    bool ok = 1;
    for (int i = (0); i < (len); ++i) {
      if (b[i].first != b[0].first) {
        ok = 0;
      }
      if (b[b.size() - 1 - i].second != b.back().second) {
        ok = 0;
      }
    }
    for (int i = (0); i < (n); ++i) {
      for (int j = (0); j < (m); ++j) {
        ss[i][j] = '.';
      }
    }
    if (ok) {
      int L = b[0].first;
      int R = b[0].second;
      if (b.size() == len) {
        res = min(res, len);
      } else {
        h = -b[len].first + b[0].second + 1;
        if (h >= 1) {
          int xx = x;
          int yy = y;
          for (int ii = (0); ii < (len); ++ii) {
            for (int jj = (0); jj < (h); ++jj) {
              ss[xx + ii][yy + jj] = 'X';
            }
          }
          while (1) {
            if (xx + len < n && s[xx + len][yy] == 'X') {
              for (int jj = (0); jj < (h); ++jj) {
                ss[xx + len][yy + jj] = 'X';
              }
              ++xx;
            } else {
              if (yy + h < m && s[xx][yy + h] == 'X') {
                for (int ii = (0); ii < (len); ++ii) {
                  ss[xx + ii][yy + h] = 'X';
                }
                ++yy;
              } else {
                break;
              }
            }
          }
        }
      }
    }
    bool g = 1;
    for (int i = (0); i < (n); ++i) {
      for (int j = (0); j < (m); ++j) {
        if (s[i][j] != ss[i][j]) {
          g = 0;
        }
      }
    }
    if (g) {
      res = min(res, len * h);
    }
  }
  if (res == INF) res = -1;
  cout << res << endl;
  return 0;
}
