#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long double EPS = 1e-9;
long long binpow(long long b, long long p, long long mod) {
  long long ans = 1;
  b %= mod;
  for (; p; p >>= 1) {
    if (p & 1) ans = ans * b % mod;
    b = b * b % mod;
  }
  return ans;
}
void pre() {}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int n, m;
int vis[1010][1010];
vector<string> arr;
bool inside(int x, int y) { return (x >= 0 && y >= 0 && y < m && x < n); }
void dfs(int x, int y, int col) {
  vis[x][y] = col;
  for (long long k = 0; k < (4); ++k) {
    if (inside(x + dx[k], y + dy[k]) && arr[x + dx[k]][y + dy[k]] == '#' &&
        vis[x + dx[k]][y + dy[k]] == 0) {
      dfs(x + dx[k], y + dy[k], col);
    }
  }
}
void solve() {
  cin >> n >> m;
  arr.resize(n);
  for (long long i = 0; i < (n); ++i) cin >> arr[i];
  bool noseedcol = 0;
  bool noseedrow = 0;
  for (long long i = 0; i < (n); ++i) {
    int cnt = 0;
    for (long long j = 0; j < (m); ++j) {
      if (arr[i][j] == '#') cnt++;
    }
    if (cnt == 0) noseedrow = 1;
  }
  for (long long j = 0; j < (m); ++j) {
    int cnt = 0;
    for (long long i = 0; i < (n); ++i) {
      if (arr[i][j] == '#') cnt++;
    }
    if (cnt == 0) noseedcol = 1;
  }
  for (long long i = 0; i < (n); ++i) {
    bool seen = 0;
    bool dot = 0;
    for (long long j = 0; j < (m); ++j) {
      if (arr[i][j] == '#') {
        if (dot && seen) {
          cout << -1 << '\n';
          return;
        } else if (!seen) {
          dot = 0;
          seen = 1;
        }
      } else {
        dot = 1;
      }
    }
  }
  for (long long j = 0; j < (m); ++j) {
    bool seen = 0;
    bool dot = 0;
    for (long long i = 0; i < (n); ++i) {
      if (arr[i][j] == '#') {
        if (dot && seen) {
          cout << -1 << '\n';
          return;
        } else if (!seen) {
          dot = 0;
          seen = 1;
        }
      } else {
        dot = 1;
      }
    }
  }
  if (noseedcol && !noseedrow) {
    cout << -1 << '\n';
    return;
  }
  if (noseedrow && !noseedcol) {
    cout << -1 << '\n';
    return;
  }
  int cnt = 0;
  for (long long i = 0; i < (n); ++i)
    for (long long j = 0; j < (m); ++j) {
      if (vis[i][j] == 0 && arr[i][j] == '#') {
        dfs(i, j, ++cnt);
      }
    }
  cout << cnt << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pre();
  long long _t = 1;
  for (long long i = 1; i <= _t; i++) {
    solve();
  }
}
