#include <bits/stdc++.h>
using namespace std;
char a[1005][1005];
bool used[1005][1005];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      char ch = getchar();
      while (ch != '.' && ch != 'X') {
        ch = getchar();
      }
      a[i][j] = ch;
    }
  }
  int ans = 1e9;
  for (int sx = 0; sx < n; ++sx) {
    for (int sy = 0; sy < m; ++sy) {
      if (a[sx][sy] == 'X') {
        {
          int x = sx, y = sy;
          int side_x = 1, side_y = 1;
          while (x + side_x < n && a[x + side_x][y] == 'X') {
            ++side_x;
          }
          while (true) {
            if (x + side_x >= n && y + side_y >= m) {
              break;
            }
            bool ok1 = true, ok2 = true;
            for (int i = 0; i < side_y; ++i) {
              if (x + side_x >= n || a[x + side_x][y + i] != 'X') {
                ok1 = false;
              }
            }
            for (int i = 0; i < side_x; ++i) {
              if (y + side_y >= m || a[x + i][y + side_y] != 'X') {
                ok2 = false;
              }
            }
            if (ok1 && ok2) {
              side_y += 1;
            } else if (ok1) {
              x += 1;
            } else if (ok2) {
              y += 1;
            } else {
              break;
            }
          }
          memset(used, false, sizeof used);
          x = sx;
          y = sy;
          for (int i = 0; i < side_x; ++i) {
            for (int j = 0; j < side_y; ++j) {
              used[x + i][y + j] = true;
            }
          }
          while (true) {
            if (x + side_x >= n && y + side_y >= m) {
              break;
            }
            bool ok1 = true, ok2 = true;
            for (int i = 0; i < side_y; ++i) {
              if (x + side_x >= n || a[x + side_x][y + i] != 'X') {
                ok1 = false;
              }
            }
            for (int i = 0; i < side_x; ++i) {
              if (y + side_y >= m || a[x + i][y + side_y] != 'X') {
                ok2 = false;
              }
            }
            if (ok1) {
              for (int i = 0; i < side_y; ++i) {
                used[x + side_x][y + i] = true;
              }
              x += 1;
            } else if (ok2) {
              for (int i = 0; i < side_x; ++i) {
                used[x + i][y + side_y] = true;
              }
              y += 1;
            } else {
              break;
            }
          }
          int s = side_x * side_y;
          for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
              if (a[i][j] == 'X') {
                if (!used[i][j]) {
                  s = 1e9;
                }
              } else {
                if (used[i][j]) {
                  s = 1e9;
                }
              }
            }
          }
          if (s < ans) {
            ans = s;
          }
        }
        {
          int x = sx, y = sy;
          int side_x = 1, side_y = 1;
          while (y + side_y < m && a[x][y + side_y] == 'X') {
            ++side_y;
          }
          while (true) {
            if (x + side_x >= n && y + side_y >= m) {
              break;
            }
            bool ok1 = true, ok2 = true;
            for (int i = 0; i < side_y; ++i) {
              if (x + side_x >= n || a[x + side_x][y + i] != 'X') {
                ok1 = false;
              }
            }
            for (int i = 0; i < side_x; ++i) {
              if (y + side_y >= m || a[x + i][y + side_y] != 'X') {
                ok2 = false;
              }
            }
            if (ok1 && ok2) {
              side_x += 1;
            } else if (ok1) {
              x += 1;
            } else if (ok2) {
              y += 1;
            } else {
              break;
            }
          }
          memset(used, false, sizeof used);
          x = sx;
          y = sy;
          for (int i = 0; i < side_x; ++i) {
            for (int j = 0; j < side_y; ++j) {
              used[x + i][y + j] = true;
            }
          }
          while (true) {
            if (x + side_x >= n && y + side_y >= m) {
              break;
            }
            bool ok1 = true, ok2 = true;
            for (int i = 0; i < side_y; ++i) {
              if (x + side_x >= n || a[x + side_x][y + i] != 'X') {
                ok1 = false;
              }
            }
            for (int i = 0; i < side_x; ++i) {
              if (y + side_y >= m || a[x + i][y + side_y] != 'X') {
                ok2 = false;
              }
            }
            if (ok1) {
              for (int i = 0; i < side_y; ++i) {
                used[x + side_x][y + i] = true;
              }
              x += 1;
            } else if (ok2) {
              for (int i = 0; i < side_x; ++i) {
                used[x + i][y + side_y] = true;
              }
              y += 1;
            } else {
              break;
            }
          }
          int s = side_x * side_y;
          for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
              if (a[i][j] == 'X') {
                if (!used[i][j]) {
                  s = 1e9;
                }
              } else {
                if (used[i][j]) {
                  s = 1e9;
                }
              }
            }
          }
          if (s < ans) {
            ans = s;
          }
        }
        if (ans == (int)1e9) {
          ans = -1;
        }
        printf("%d\n", ans);
        return 0;
      }
    }
  }
  return 0;
}
