#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
char c[N][N];
long long okc[N], okr[N], vis[N][N], n, m;
long long mu[4] = {0, 0, 1, -1};
long long mv[4] = {1, -1, 0, 0};
void dfs(long long u, long long v) {
  vis[u][v] = 1;
  for (int i = 0; i < 4; i++) {
    if ((u + mu[i]) <= n && (u + mu[i]) >= 1 && (v + mv[i]) >= 1 &&
        (v + mv[i]) <= m && vis[u + mu[i]][v + mv[i]] == 0 &&
        c[u + mu[i]][v + mv[i]] == '#') {
      dfs(u + mu[i], v + mv[i]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (fopen("KIENDT.INP", "r")) {
    freopen("KIENDT.INP", "r", stdin);
    freopen("KIENDT.OUT", "w", stdout);
  }
  cin >> n >> m;
  bool flag = true;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
      if (okr[i] == 1 && c[i][j] == '#' && j > 1 && c[i][j - 1] == '.')
        flag = false;
      if (c[i][j] == '#') okr[i] = 1;
      if (okc[j] == 1 && c[i][j] == '#' && i > 1 && c[i - 1][j] == '.')
        flag = false;
      if (c[i][j] == '#') okc[j] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (okr[i] == 1) continue;
    bool ok = false;
    for (int j = 1; j <= m; j++) {
      if (okc[j] == 0) ok = true;
    }
    if (!ok) flag = false;
  }
  for (int j = 1; j <= m; j++) {
    if (okc[j] == 1) continue;
    bool ok = false;
    for (int i = 1; i <= n; i++) {
      if (okr[i] == 0) ok = true;
    }
    if (!ok) flag = false;
  }
  if (!flag)
    cout << -1;
  else {
    long long cnt = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (vis[i][j] == 0 && c[i][j] == '#') {
          dfs(i, j);
          cnt++;
        }
      }
    }
    cout << cnt;
  }
}
