#include <bits/stdc++.h>
using namespace std;
char a[1005][1005];
bool vis[1005][1005];
int n, m;
int check(string s) {
  int i;
  for (i = 0; i < s.size(); i++) {
    if (i + 1 < s.size() && s[i] == '#' && s[i + 1] == '.') {
      break;
    }
  }
  i++;
  for (; i < s.size(); i++) {
    if (s[i] == '#') {
      cout << -1 << endl;
      exit(0);
    }
  }
}
void dfs(int i, int j) {
  if (i < 0 || i >= n || j < 0 || j >= m) return;
  if (a[i][j] == '.' || vis[i][j]) return;
  vis[i][j] = true;
  dfs(i + 1, j);
  dfs(i - 1, j);
  dfs(i, j + 1);
  dfs(i, j - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) cin >> a[i][j];
    }
    int a1 = 0, b1 = 0;
    for (int i = 0; i < n; i++) {
      string s = "";
      for (int j = 0; j < m; j++) s += a[i][j];
      check(s);
      if (a1 == 0) {
        for (int j = 0; j < m; j++) {
          if (s[j] == '.') {
            a1 = 1;
            continue;
          } else {
            a1 = 0;
            break;
          }
        }
      }
    }
    for (int j = 0; j < m; j++) {
      string s = "";
      for (int i = 0; i < n; i++) s += a[i][j];
      check(s);
      if (b1 == 0) {
        for (int i = 0; i < n; i++) {
          if (s[i] == '.') {
            b1 = 1;
            continue;
          } else {
            b1 = 0;
            break;
          }
        }
      }
    }
    if (a1 != b1) {
      cout << -1 << endl;
      exit(0);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (!vis[i][j] && a[i][j] == '#') {
          ans++;
          dfs(i, j);
        }
      }
    }
    cout << ans << endl;
  }
  cerr << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << "ms"
       << '\n';
  return 0;
}
