#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
double eps = 1e-10;
long long INF = 0x3f3f3f3f;
const int MAXN = 2e3 + 10;
const int maxn = 1e5 + 10;
long long inf = 100000000000000;
char mp[1010][1010];
void dfs(int i, int j) {
  mp[i][j] = '.';
  if (mp[i + 1][j] == '#') dfs(i + 1, j);
  if (mp[i][j + 1] == '#') dfs(i, j + 1);
  if (mp[i - 1][j] == '#') dfs(i - 1, j);
  if (mp[i][j - 1] == '#') dfs(i, j - 1);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", mp[i] + 1);
  int row = 0, col = 0;
  bool has = 1;
  for (int i = 1; i <= n; i++) {
    bool ok = 0;
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '#') {
        ok = 1;
        break;
      }
    }
    row += ok;
  }
  for (int j = 1; j <= m; j++) {
    bool ok = 0;
    for (int i = 1; i <= n; i++) {
      if (mp[i][j] == '#') {
        ok = 1;
        break;
      }
    }
    col += ok;
  }
  for (int i = 1; i <= n; i++) {
    int l = -1, r = -1;
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '#') {
        if (l != -1)
          r = j;
        else
          l = r = j;
      }
    }
    if (l == -1) {
      if (col == m) has = 0;
      continue;
    }
    for (int j = l; j <= r; j++) {
      if (mp[i][j] != '#') {
        has = 0;
        break;
      }
    }
  }
  for (int j = 1; j <= m; j++) {
    int l = -1, r = -1;
    for (int i = 1; i <= n; i++) {
      if (mp[i][j] == '#') {
        if (l != -1)
          r = i;
        else
          l = r = i;
      }
    }
    if (l == -1) {
      if (row == n) has = 0;
      continue;
    }
    for (int i = l; i <= r; i++) {
      if (mp[i][j] != '#') {
        has = 0;
        break;
      }
    }
  }
  if (has == 0) return 0 * puts("-1");
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '#') dfs(i, j), ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
