#include <bits/stdc++.h>
using namespace std;
int o[1100][1100], ck[1100][1100];
int col[1100], row[1100];
int di[4] = {-1, 1, 0, 0};
int dj[4] = {0, 0, -1, 1};
int a, b;
void dfs(int xi, int xj) {
  col[xj] = row[xi] = true;
  ck[xi][xj] = true;
  for (int k = 0; k < 4; k++) {
    int ni = xi + di[k];
    int nj = xj + dj[k];
    if (0 <= ni && ni < a) {
      if (0 <= nj && nj < b) {
        if (ck[ni][nj] == false) {
          if (o[ni][nj] == '#') {
            dfs(ni, nj);
          }
        }
      }
    }
  }
}
int main(void) {
  scanf("%d %d", &a, &b);
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      scanf(" %c", &o[i][j]);
    }
  }
  int noflag = false;
  for (int i = 0; i < a; i++) {
    int left = 0, right = b - 1;
    while (o[i][left] == '.') left++;
    while (o[i][right] == '.') right--;
    for (int j = left; j <= right; j++) {
      if (o[i][j] == '.') {
        noflag = true;
      }
    }
  }
  for (int j = 0; j < b; j++) {
    for (int i = 0; i < a; i++) {
      int left = 0, right = a - 1;
      while (o[left][j] == '.') left++;
      while (o[right][j] == '.') right--;
      for (int i = left; i <= right; i++) {
        if (o[i][j] == '.') {
          noflag = true;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      if (!ck[i][j] && o[i][j] == '#') {
        ans++;
        dfs(i, j);
      }
    }
  }
  int empty_row_exist = false, empty_col_exist = false;
  for (int i = 0; i < a; i++) {
    if (!row[i]) {
      empty_row_exist = true;
    }
  }
  for (int i = 0; i < b; i++) {
    if (!col[i]) {
      empty_col_exist = true;
    }
  }
  if (empty_row_exist ^ empty_col_exist) noflag = true;
  if (noflag)
    printf("-1\n");
  else
    printf("%d\n", ans);
}
