#include <bits/stdc++.h>
using namespace std;
char a[1001][1001];
int visit[1001][1001];
void dfs(int i, int j, int n, int m, int cc) {
  visit[i][j] = cc;
  if (i != 0 && a[i - 1][j] == '#' && visit[i - 1][j] == -1)
    dfs(i - 1, j, n, m, cc);
  if (j != 0 && a[i][j - 1] == '#' && visit[i][j - 1] == -1)
    dfs(i, j - 1, n, m, cc);
  if (i != n - 1 && a[i + 1][j] == '#' && visit[i + 1][j] == -1)
    dfs(i + 1, j, n, m, cc);
  if (j != m - 1 && a[i][j + 1] == '#' && visit[i][j + 1] == -1)
    dfs(i, j + 1, n, m, cc);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int rowflag = 0, f = 1, colflag = 0, c = 0, b = 0;
  for (i = 0; i < n; i++) {
    rowflag = 0;
    c = 0;
    for (j = 0; j < m; j++) {
      if (rowflag == 1 && a[i][j] == '#') f = 0;
      if (rowflag == 0 && a[i][j] == '#' && (j < m - 1 && a[i][j + 1] == '.'))
        rowflag = 1;
      if (a[i][j] == '.') c++;
    }
    if (c == m) b = 1;
  }
  int g = 0, h = 0;
  for (i = 0; i < m; i++) {
    colflag = 0;
    g = 0;
    for (j = 0; j < n; j++) {
      if (colflag == 1 && a[j][i] == '#') f = 0;
      if (colflag == 0 && a[j][i] == '#' && (j < n - 1 && a[j + 1][i] == '.'))
        colflag = 1;
      if (a[j][i] == '.') g++;
    }
    if (g == n) h = 1;
  }
  if (f == 0 || h == 1 && b == 0 || b == 1 && h == 0)
    cout << "-1";
  else {
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        visit[i][j] = -1;
      }
    }
    int cc = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (a[i][j] == '#' && visit[i][j] == -1) {
          cc++;
          dfs(i, j, n, m, cc);
        }
      }
    }
    cout << cc << endl;
  }
  return 0;
}
