#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
char s[1010][1010];
int vis[1010][1010];
int n, m;
void dfs(int x, int y) {
  if (x <= 0 || x > n || y <= 0 || y > m) return;
  if (vis[x][y] || s[x][y] == '.') return;
  vis[x][y] = 1;
  dfs(x - 1, y);
  dfs(x + 1, y);
  dfs(x, y - 1);
  dfs(x, y + 1);
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  int su = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '#') su++;
    }
  }
  int fg = 1, ffg = 0;
  for (int i = 1; i <= n; i++) {
    int mk = 0;
    for (int j = 1; j <= m; j++) {
      if (mk == 0) {
        if (s[i][j] == '#') mk = 1;
      } else if (mk == 1) {
        if (s[i][j] != '#') mk = 2;
      } else if (mk == 2) {
        if (s[i][j] == '#') mk = -1;
      }
    }
    if (mk == -1) fg = 0;
    if (mk == 0) ffg |= 1;
  }
  for (int j = 1; j <= m; j++) {
    int mk = 0;
    for (int i = 1; i <= n; i++) {
      if (mk == 0) {
        if (s[i][j] == '#') mk = 1;
      } else if (mk == 1) {
        if (s[i][j] != '#') mk = 2;
      } else if (mk == 2) {
        if (s[i][j] == '#') mk = -1;
      }
    }
    if (mk == -1) fg = 0;
    if (mk == 0) ffg |= 2;
  }
  if (!fg || ffg == 2 || ffg == 1) {
    if (su)
      printf("-1\n");
    else
      printf("0\n");
  } else {
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (!vis[i][j] && s[i][j] == '#') {
          ans++;
          dfs(i, j);
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
