#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e3 + 5;
long long n, m, r[maxn], c[maxn], zeror, zeroc,
    sol = 1, ncc, dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
tuple<long long, long long> q[maxn * maxn];
string s[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (long long i = (0); i < (n); i++) cin >> s[i];
  for (long long i = (0); i < (n); i++) {
    long long seg = 0;
    for (long long j = (0); j < (m); j++) {
      if (s[i][j] == '#' && !seg) seg = 1, r[i]++;
      if (s[i][j] == '.') seg = 0;
    }
  }
  for (long long j = (0); j < (m); j++) {
    long long seg = 0;
    for (long long i = (0); i < (n); i++) {
      if (s[i][j] == '#' && !seg) seg = 1, c[j]++;
      if (s[i][j] == '.') seg = 0;
    }
  }
  for (long long i = (0); i < (n); i++)
    if (r[i] == 0) zeror = 1;
  for (long long i = (0); i < (m); i++)
    if (c[i] == 0) zeroc = 1;
  for (long long i = (0); i < (n); i++)
    if (r[i] > 1 || r[i] < 1 && !zeroc) sol = 0;
  for (long long i = (0); i < (m); i++)
    if (c[i] > 1 || c[i] < 1 && !zeror) sol = 0;
  for (long long i = (0); i < (n); i++)
    for (long long j = (0); j < (m); j++)
      if (s[i][j] == '#') {
        long long b = 0, e = 0;
        q[e++] = {i, j}, s[i][j] = '.';
        while (b < e) {
          auto [x, y] = q[b++];
          for (long long k = (0); k < (4); k++) {
            long long x2 = x + dx[k], y2 = y + dy[k];
            if (0 <= x2 && x2 < n && 0 <= y2 && y2 < m && s[x2][y2] == '#')
              q[e++] = {x2, y2}, s[x2][y2] = '.';
          }
        }
        ncc++;
      }
  if (!sol)
    cout << "-1\n";
  else
    cout << ncc << "\n";
}
