#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m;
char s[N][N];
void dfs(int i, int j) {
  if (i < 0 || i == n || j < 0 || j == m || s[i][j] == '.') return;
  s[i][j] = '.';
  dfs(i, j + 1);
  dfs(i, j - 1);
  dfs(i + 1, j), dfs(i - 1, j);
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  int r = 0, c = 0;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < m; j++) cnt += s[i][j] == '#';
    if (cnt == 0) r++;
    cnt = 0;
    for (int j = 0; j < m; j++)
      if (s[i][j] == '#' && (j == 0 || s[i][j - 1] == '.')) cnt++;
    if (cnt > 1) {
      printf("-1\n");
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) cnt += s[j][i] == '#';
    if (cnt == 0) c++;
    cnt = 0;
    for (int j = 0; j < n; j++)
      if (s[j][i] == '#' && (j == 0 || s[j - 1][i] == '.')) cnt++;
    if (cnt > 1) {
      printf("-1\n");
      return 0;
    }
  }
  if (r == n && c == m) {
    printf("0\n");
    return 0;
  }
  if (r > 0 && c == 0 || c > 0 && r == 0) {
    printf("-1\n");
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (s[i][j] == '#') {
        ans++;
        dfs(i, j);
      }
  printf("%d\n", ans);
  return 0;
}
