#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> s(1001);
bool vis[1001][1001];
int first[] = {0, 0, 1, -1};
int second[] = {1, -1, 0, 0};
void run(int i, int j, int n, int m) {
  if (i < 0 || i >= n || j < 0 || j >= m || s[i][j] == '.' || vis[i][j]) return;
  vis[i][j] = true;
  for (int k = 0; k < 4; k++) {
    int I = i + first[k], J = j + second[k];
    run(I, J, n, m);
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    int l = 0;
    int r = 0;
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '#') {
        l = j;
        break;
      }
    }
    for (int j = m - 1; j >= 0; j--) {
      if (s[i][j] == '#') {
        r = j;
        break;
      }
    }
    for (int j = l + 1; j < r; j++) {
      if (s[i][j] == '.') {
        cout << -1;
        return;
      }
    }
  }
  for (int j = 0; j < m; j++) {
    int l = 0;
    int r = 0;
    for (int i = 0; i < n; i++) {
      if (s[i][j] == '#') {
        l = i;
        break;
      }
    }
    for (int i = n - 1; i >= 0; i--) {
      if (s[i][j] == '#') {
        r = i;
        break;
      }
    }
    for (int i = l + 1; i < r; i++) {
      if (s[i][j] == '.') {
        cout << -1;
        return;
      }
    }
  }
  bool allwr = false;
  bool allwc = false;
  for (int i = 0; i < n; i++) {
    bool t = true;
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '#') {
        t = false;
        break;
      }
    }
    if (t) {
      allwr = true;
      break;
    }
  }
  for (int j = 0; j < m; j++) {
    bool kk = true;
    for (int i = 0; i < n; i++) {
      if (s[i][j] == '#') {
        kk = false;
        break;
      }
    }
    if (kk) {
      allwc = true;
      break;
    }
  }
  if (allwr ^ allwc) {
    cout << -1;
    return;
  }
  if (n == 1 || m == 1) {
    char c = s[0][0];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (s[i][j] != c) {
          cout << -1;
          return;
        }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) vis[i][j] = false;
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '#' && !vis[i][j]) {
        ans++;
        run(i, j, n, m);
      }
    }
  cout << ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
