#include <bits/stdc++.h>
using namespace std;
int a[1005][1005], n, H[1005], C[1005], sl, u, v, f[1000005], m, ru, rv, l, r;
char kitu;
bool kq[1005][1005], check, cc, kt[1000005], kth[1005], ktc[1005];
int phin(int u) { return f[u] < 0 ? u : f[u] = phin(f[u]); }
void uni(int u, int v) {
  if (f[u] > f[v]) swap(u, v);
  f[u] += f[v];
  f[v] = u;
}
int tinh(int u, int v) { return (u - 1) * m + v; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      cin >> kitu;
      if (kitu == '#')
        a[i][j] = 2;
      else
        a[i][j] = 1;
      H[i] += a[i][j];
      C[j] += a[i][j];
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (H[i] == m && C[j] == n) {
        kq[i][j] = true;
        kth[i] = ktc[j] = true;
      }
  memset(f, -1, sizeof(f));
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (a[i][j] == 2) {
        kq[i][j] = true;
        u = tinh(i, j);
        if (i > 1 && a[i - 1][j] == 2) {
          v = tinh(i - 1, j);
          ru = phin(u);
          rv = phin(v);
          if (ru != rv) uni(ru, rv);
        }
        if (j > 1 && a[i][j - 1] == 2) {
          v = tinh(i, j - 1);
          ru = phin(u);
          rv = phin(v);
          if (ru != rv) uni(ru, rv);
        }
      }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (a[i][j] == 2) {
        u = tinh(i, j);
        ru = phin(u);
        if (!kt[ru]) {
          sl++;
          kt[ru] = true;
        }
      }
  cc = true;
  for (int i = 1; i <= n; ++i) {
    check = false;
    for (int j = 1; j <= m; ++j)
      if (kq[i][j]) check = true;
    if (!check) {
      cc = false;
      break;
    }
    if (kth[i]) continue;
    for (int j = 1; j <= m; ++j)
      if (kq[i][j]) {
        l = j;
        break;
      }
    for (int j = m; j >= 1; --j)
      if (kq[i][j]) {
        r = j;
        break;
      }
    for (int j = l; j <= r; ++j)
      if (a[i][j] == 1) cc = false;
  }
  for (int j = 1; j <= m; ++j) {
    check = false;
    for (int i = 1; i <= n; ++i)
      if (kq[i][j]) check = true;
    if (!check) {
      cc = false;
      break;
    }
    if (ktc[j]) continue;
    for (int i = 1; i <= n; ++i)
      if (kq[i][j]) {
        l = i;
        break;
      }
    for (int i = n; i >= 1; --i)
      if (kq[i][j]) {
        r = i;
        break;
      }
    for (int i = l; i <= r; ++i)
      if (a[i][j] == 1) cc = false;
  }
  if (!cc)
    cout << -1;
  else
    cout << sl;
  return 0;
}
