#include <bits/stdc++.h>
using namespace std;
char a[1005][1005];
long long n, m, vis[1005][1005];
long long r[1005], c[1005], ar[1005], ac[1005];
const long long dx[4] = {0, 1, 0, -1};
const long long dy[4] = {1, 0, -1, 0};
bool isvalid(long long x, long long y) {
  return x >= 1 and y >= 1 and x <= n and y <= m and a[x][y] == '#';
}
void dfs(long long x, long long y) {
  a[x][y] = '.';
  for (long long j = 0; j < 4; j++) {
    long long cx = x + dx[j];
    long long cy = y + dy[j];
    if (isvalid(cx, cy)) dfs(cx, cy);
  }
}
void solve() {
  cin >> n >> m;
  memset(vis, 0, sizeof vis);
  for (long long i = 1; i < n + 1; i++)
    for (long long j = 1; j < m + 1; j++) cin >> a[i][j];
  for (long long i = 1; i < n + 1; i++)
    for (long long j = 1; j < m + 1; j++)
      if (a[i][j] == '#') r[i] = c[j] = 1;
  for (long long i = 1; i < n + 1; i++)
    for (long long j = 1; j < m + 1; j++) {
      if (!r[i] and !c[j]) ar[i] = ac[j] = 1;
    }
  for (long long i = 1; i < n + 1; i++)
    if (!r[i] and !ar[i]) {
      cout << -1 << '\n';
      return;
    }
  for (long long j = 1; j < m + 1; j++)
    if (!c[j] and !ac[j]) {
      cout << -1 << '\n';
      return;
    }
  for (long long i = 1; i < n + 1; i++) {
    long long st = m + 1, en = 0;
    for (long long j = 1; j < m + 1; j++)
      if (a[i][j] == '#') {
        st = min(st, j);
        en = max(en, j);
      }
    for (long long j = st; j < en + 1; j++)
      if (a[i][j] == '.') {
        cout << -1 << '\n';
        return;
      }
  }
  for (long long j = 1; j < m + 1; j++) {
    long long st = n + 1, en = 0;
    for (long long i = 1; i < n + 1; i++)
      if (a[i][j] == '#') {
        st = min(st, i);
        en = max(en, i);
      }
    for (long long i = st; i < en + 1; i++)
      if (a[i][j] == '.') {
        cout << -1 << '\n';
        return;
      }
  }
  long long ans = 0;
  for (long long i = 1; i < n + 1; i++)
    for (long long j = 1; j < m + 1; j++)
      if (isvalid(i, j)) {
        dfs(i, j);
        ans++;
      }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long TESTS = 1;
  while (TESTS--) {
    solve();
  }
  return 0;
}
