#include <bits/stdc++.h>
using namespace std;
int n, m;
const int maxn = 2010;
char save[maxn][maxn];
int res = 0;
int dis[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
struct node {
  int x;
  int y;
  node(){};
  node(int a, int b) { x = a, y = b; }
};
void dfs(int x, int y) {
  save[x][y] = '.';
  for (int i = 0; i < 4; i++) {
    int xx = x + dis[i][0];
    int yy = y + dis[i][1];
    if (xx < 1 || yy < 1 || xx > n || yy > m) continue;
    if (save[xx][yy] == '.') continue;
    dfs(xx, yy);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", save[i] + 1);
  int rok = 1, cok = 1, haver = 0, havec = 0;
  for (int i = 1; i <= n; i++) {
    int last = -1;
    for (int j = 1; j <= m; j++) {
      if (save[i][j] == '#') {
        if (last != -1 && last != j - 1) {
          cok = 0;
          break;
        }
        last = j;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    int last = -1;
    for (int j = 1; j <= n; j++) {
      if (save[j][i] == '#') {
        if (last != -1 && last != j - 1) {
          rok = 0;
          break;
        }
        last = j;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int ok = 0;
    for (int j = 1; j <= m; j++) {
      if (save[i][j] == '#') ok = 1;
    }
    if (ok == 0) haver = 1;
  }
  for (int j = 1; j <= m; j++) {
    int ok = 0;
    for (int i = 1; i <= n; i++) {
      if (save[i][j] == '#') ok = 1;
    }
    if (ok == 0) havec = 1;
  }
  if (rok == 0 || cok == 0 || havec ^ haver == 1) {
    printf("-1");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (save[i][j] == '#') {
        res++;
        dfs(i, j);
      }
    }
  }
  printf("%d", res);
  return 0;
}
