#include <bits/stdc++.h>
int map[1001][1001];
int n, m;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, -1, 1};
inline bool check(int x, int y) {
  return (x >= 1 && x <= n && y >= 1 && y <= m);
}
void dfs(int x, int y) {
  for (int i = 0; i < 4; i++)
    if (check(x + dx[i], y + dy[i]) && map[x + dx[i]][y + dy[i]]) {
      map[x + dx[i]][y + dy[i]] = 0;
      dfs(x + dx[i], y + dy[i]);
    }
}
int main() {
  scanf("%d %d\n", &n, &m);
  char c;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%c", &c);
      if (c == '#')
        map[i][j] = 1;
      else
        map[i][j] = 0;
    }
    scanf("%c", &c);
  }
  bool check = true;
  bool checks = true;
  bool check1 = true, check2 = true;
  for (int i = 1; i <= n; i++) {
    int jugde = 0;
    bool check1s = true;
    for (int j = 1; j <= m; j++) {
      if (map[i][j] == 1) check1s = false, checks = false;
      if (!jugde && map[i][j] == 1) jugde = 1;
      if (jugde == 1 && map[i][j] == 0) jugde = 2;
      if (jugde == 2 && map[i][j] == 1) check = false;
    }
    if (check1s) check1 = false;
  }
  for (int j = 1; j <= m; j++) {
    int jugde = 0;
    bool check2s = true;
    for (int i = 1; i <= n; i++) {
      if (map[i][j] == 1) check2s = false;
      if (!jugde && map[i][j] == 1) jugde = 1;
      if (jugde == 1 && map[i][j] == 0) jugde = 2;
      if (jugde == 2 && map[i][j] == 1) check = false;
    }
    if (check2s) check2 = false;
  }
  if ((!check || (check1 ^ check2)) && !checks) {
    printf("-1");
    return 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (map[i][j]) {
        ans++;
        dfs(i, j);
      }
  }
  printf("%d", ans);
  return 0;
}
