#include <bits/stdc++.h>
using namespace std;
int n, m, emrow = 0, emcol = 0;
char a[1005][1005];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
void In() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
}
void checkrow() {
  for (int i = 1; i <= n; i++) {
    int tmp = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '#' && (j == 1 || a[i][j - 1] == '.')) tmp++;
    }
    if (tmp > 1) {
      cout << -1;
      exit(0);
    }
    if (tmp == 0) emrow++;
  }
}
void checkcol() {
  for (int i = 1; i <= m; i++) {
    int tmp = 0;
    for (int j = 1; j <= n; j++) {
      if (a[j][i] == '#' && (j == 1 || a[j - 1][i] == '.')) tmp++;
    }
    if (tmp > 1) {
      cout << -1;
      exit(0);
    }
    if (tmp == 0) emcol++;
  }
}
void Solve() {
  checkrow();
  checkcol();
  if ((emcol > 0) != (emrow > 0)) {
    cout << -1;
    exit(0);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == '#') {
        ans++;
        queue<pair<int, int> > qu;
        qu.emplace(i, j);
        while (!qu.empty()) {
          int x = qu.front().first;
          int y = qu.front().second;
          qu.pop();
          for (int t = 0; t < 4; t++) {
            int u = x + dx[t];
            int v = y + dy[t];
            if (u >= 1 && v >= 1 && v <= m && u <= n && a[u][v] == '#') {
              a[u][v] = '.';
              qu.emplace(u, v);
            }
          }
        }
      }
  cout << ans;
}
int main() {
  In();
  Solve();
}
