#include <bits/stdc++.h>
const int N = 1e3 + 5;
const int d[][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
char _[N][N];
bool vis[N][N];
int n, m;
bool dfs(int x, int y) {
  if (vis[x][y] || _[x][y] == '.') return 0;
  vis[x][y] = 1;
  for (const int* i : d) {
    int now_x = x + *i, now_y = y + *(i + 1);
    if (now_x <= 0 || now_y <= 0 || now_x > n || now_y > m) continue;
    dfs(now_x, now_y);
  }
  return 1;
}
int main() {
  scanf("%d %d\n", &n, &m);
  for (auto i = (1); i <= (n); ++i) {
    fgets(_[i] + 1, m + 1, stdin);
    if (_[i][1] == 10) fgets(_[i] + 1, m + 1, stdin);
  }
  int while_line = 0, while_col = 0;
  for (int i = 1, f; i <= n; ++i) {
    f = 1;
    for (auto j = (1); j <= (m); ++j)
      if (_[i][j] == '#') f = 0;
    while_line += f;
  }
  for (int i = 1, f; i <= m; ++i) {
    f = 1;
    for (auto j = (1); j <= (n); ++j)
      if (_[j][i] == '#') f = 0;
    while_col += f;
  }
  if ((while_line == 0) ^ (while_col == 0)) {
    puts("-1");
    return 0;
  }
  for (int i = 1, l, r; i <= n; ++i) {
    l = r = 0;
    for (auto j = (1); j <= (m); ++j)
      if (_[i][j] == '#') {
        l = j;
        break;
      }
    for (auto j = (m); j >= (1); --j)
      if (_[i][j] == '#') {
        r = j;
        break;
      }
    for (auto j = (l); j <= (r); ++j)
      if (_[i][j] == '.') {
        puts("-1");
        return 0;
      }
  }
  for (int i = 1, l, r; i <= m; ++i) {
    l = r = 0;
    for (auto j = (1); j <= (n); ++j)
      if (_[j][i] == '#') {
        l = j;
        break;
      }
    for (auto j = (n); j >= (1); --j)
      if (_[j][i] == '#') {
        r = j;
        break;
      }
    for (auto j = (l); j <= (r); ++j)
      if (_[j][i] == '.') {
        puts("-1");
        return 0;
      }
  }
  int cnt = 0;
  for (auto i = (1); i <= (n); ++i)
    for (auto j = (1); j <= (m); ++j) cnt += dfs(i, j);
  printf("%d\n", cnt);
  return 0;
}
