#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 7, INF = 1e9;
char a[1000][1000];
bool check(vector<char> v) {
  if (!count(v.begin(), v.end(), '#')) return 1;
  long long l = find(v.begin(), v.end(), '#') - v.begin();
  long long r = l;
  for (long long i = 0; i < v.size(); ++i)
    if (v[i] == '#') l = min(l, i), r = max(r, i);
  return !count(v.begin() + l, v.begin() + r, '.');
}
long long cmp = 0;
long long vis[1000][1000];
long long n, m;
void dfs(pair<long long, long long> v) {
  if (v.first >= n || v.first < 0 || v.second < 0 || v.second >= m ||
      a[v.first][v.second] == '.' || vis[v.first][v.second] != -1)
    return;
  vis[v.first][v.second] = cmp;
  dfs({v.first + 1, v.second});
  dfs({v.first - 1, v.second});
  dfs({v.first, v.second + 1});
  dfs({v.first, v.second - 1});
}
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < n; ++i)
    for (long long j = 0; j < m; ++j) cin >> a[i][j], vis[i][j] = -1;
  bool ok = 1;
  long long c1 = 0, c2 = 0;
  for (long long i = 0; i < n; ++i) {
    if (!check(vector<char>(a[i], a[i] + m)))
      ok = 0;
    else if (!count(a[i], a[i] + m, '#'))
      c1 = 1;
  }
  for (long long i = 0; i < m; ++i) {
    vector<char> curr;
    for (long long j = 0; j < n; ++j) curr.push_back(a[j][i]);
    if (!check(curr))
      ok = 0;
    else if (!count(curr.begin(), curr.end(), '#'))
      c2 = 1;
  }
  if (!ok || (c1 ^ c2)) {
    cout << "-1";
    return;
  }
  for (long long i = 0; i < n; ++i)
    for (long long j = 0; j < m; ++j)
      if (a[i][j] == '#' && vis[i][j] == -1) {
        dfs({i, j});
        cmp++;
      }
  cout << cmp;
  return;
}
signed main() {
  ios::sync_with_stdio(false);
  long long t = 1;
  for (long long i = 0; i < t; ++i) solve();
  return 0;
}
