#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
bool FLAG = 0;
using namespace std;
const int MOD = (int)1e9 + 7, N = (int)2e6 + 222;
const long long INF = (int)1e9;
int dx[] = {0, -1, 0, 1, 0};
int dy[] = {0, 0, 1, 0, -1};
int n, m, x[N], y[N], mn[1111][1111], mx[1111][1111], mn1[1111][1111],
    mx1[1111][1111], pref[1111][1111], pref1[1111][1111], used[1111][1111];
char a[1111][1111];
queue<pair<int, int> > q;
void calc() {
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    for (int i = 1; i <= 4; ++i) {
      if (x + dx[i] >= 1 && x + dx[i] <= n) {
        if (y + dy[i] >= 1 && y + dy[i] <= m) {
          if (used[x + dx[i]][y + dy[i]] == 0 &&
              a[x + dx[i]][y + dy[i]] == '#') {
            used[x + dx[i]][y + dy[i]] = 1;
            q.push({x + dx[i], y + dy[i]});
          }
        }
      }
    }
  }
}
inline void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    mx[i][0] = -INF;
    mn[i][0] = INF;
  }
  for (int j = 1; j <= m; ++j) {
    mx1[0][j] = -INF;
    mn1[0][j] = INF;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      if (a[i][j] == '#') {
        pref[i][j]++;
        pref1[i][j]++;
        mx1[i][j] = i;
        mx[i][j] = j;
        mn1[i][j] = min(mn1[i - 1][j], i);
        mn[i][j] = min(mn[i][j - 1], j);
      } else {
        mn[i][j] = mn[i][j - 1];
        mn1[i][j] = mn1[i - 1][j];
        mx[i][j] = mx[i][j - 1];
        mx1[i][j] = mx1[i - 1][j];
      }
      pref[i][j] += pref[i][j - 1];
      pref1[i][j] += pref1[i - 1][j];
    }
  }
  int col = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (a[i][j] == '#' && used[i][j] == 0) {
        used[i][j] = 1;
        col++;
        q.push({i, j});
        calc();
      }
      if (a[i][j] == '#') {
        int l = mn[i][j], r = mx[i][m];
        if (r - l + 1 == pref[i][r] - pref[i][l - 1]) {
          int l1 = mn1[i][j], r1 = mx1[n][j];
          if (r1 - l1 + 1 == pref1[r1][j] - pref1[l1 - 1][j]) {
            x[i] = 1;
            y[j] = 1;
          }
        }
      } else {
        if (pref[i][m] == 0 && pref1[n][j] == 0) {
          x[i] = 1;
          y[j] = 1;
        }
      }
    }
  }
  bool ok = 0;
  for (int i = 1; i <= n; ++i)
    if (x[i] == 0) ok = 1;
  for (int i = 1; i <= m; ++i)
    if (y[i] == 0) ok = 1;
  if (ok == 1) {
    cout << -1;
    return;
  }
  cout << col;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
