#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = (ll)998244353;
const int INF = 1e9 + 1;
const int N = 1e6 + 100;
const double eps = 1e-7;
int power(int a, int b) {
  if (!b) return 1;
  int c = power(a, b / 2) % mod;
  c = (1LL * c * c);
  if (b % 2) c = (1LL * c * a) % mod;
  return c;
}
int mul(int a, int b) { return a * 1ll * b % mod; }
void done() {
  ll n, k, s;
  cin >> n >> k >> s;
  if (s < k || s > (n - 1) * k) {
    cout << "NO" << '\n';
    return;
  }
  cout << "YES" << '\n';
  if (k == 1) {
    cout << s + 1 << '\n';
    return;
  }
  ll p = (s + k - 1) / k;
  int st = 0;
  ll cur = 1;
  ll tot = p * k;
  for (int i = 0; i < k - (tot > s); ++i) {
    if (st == 0) {
      cout << cur + p << ' ';
      cur += p;
      st = 1;
    } else {
      cout << cur - p << ' ';
      cur -= p;
      st = 0;
    }
  }
  ll lp = tot - s;
  if (tot > s) {
    cout << (st == 0 ? cur + p - lp : cur - (p - lp)) << ' ';
  }
}
void solve() {}
void another() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; ++i) cin >> s[i];
  vector<bool> rows(w, false), cols(h, false);
  int ans = 0;
  vector<vector<bool>> vis(h, vector<bool>(w, 0));
  vector<pair<int, int>> directions{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
  auto inside = [&](int i, int j) {
    return (i > -1 && j > -1 && i < h && j < w);
  };
  function<void(int, int)> dfs = [&](int i, int j) {
    vis[i][j] = true;
    for (auto dir : directions) {
      int pi = i + dir.first;
      int pj = j + dir.second;
      if (inside(pi, pj) && !vis[pi][pj] && s[pi][pj] == '#') {
        dfs(pi, pj);
      }
    }
  };
  for (int i = 0; i < h; ++i) {
    bool ok = 1;
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#') {
        rows[j] = true;
        cols[i] = true;
        if (ok) {
          ok = 0;
        } else if (s[i][j - 1] == '#')
          continue;
        else {
          cout << -1 << '\n';
          return;
        }
      }
    }
    if (!ok) cols[i] = true;
  }
  for (int j = 0; j < w; ++j) {
    bool ok = 1;
    for (int i = 0; i < h; ++i) {
      if (s[i][j] == '#') {
        if (ok) {
          ok = 0;
          continue;
        }
        if (s[i - 1][j] != '#') {
          cout << -1 << '\n';
          return;
        }
      }
    }
  }
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#' && !vis[i][j]) {
        dfs(i, j);
        ++ans;
      }
    }
  for (int i = 0; i < h; ++i) {
    if (!cols[i]) {
      bool bad = 1;
      for (int j = 0; j < w; ++j) {
        if (!rows[j]) {
          bad = 0;
          break;
        }
      }
      if (bad) {
        cout << -1 << '\n';
        return;
      }
    }
  }
  for (int j = 0; j < w; ++j) {
    if (!rows[j]) {
      bool bad = 1;
      for (int i = 0; i < h; ++i) {
        if (!cols[i]) {
          bad = 0;
          break;
        }
      }
      if (bad) {
        cout << -1 << '\n';
        return;
      }
    }
  }
  cout << ans << '\n';
}
void test_case() {
  int t;
  cin >> t;
  while (t--) another();
}
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  another();
}
