#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
const long long Mod = 998244353;
int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
string s[maxn];
int a[1005][1005];
int v[1005][1005];
int n, m;
void dfs(int x, int y) {
  v[x][y] = 1;
  int xx, yy;
  for (int i = 0; i < 4; i++) {
    xx = x + d[i][0];
    yy = y + d[i][1];
    if (xx < 1 || xx > n || yy < 1 || yy > m) continue;
    if (a[xx][yy] == 0) continue;
    if (v[xx][yy]) continue;
    dfs(xx, yy);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int f = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i - 1][j - 1] == '#')
        a[i][j] = 1;
      else
        a[i][j] = 0;
    }
  }
  int ff = 0;
  int cf = 0, rf = 0;
  for (int i = 1; i <= n; i++) {
    ff = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == 1) {
        ff = 1;
        break;
      }
    }
    if (ff == 0) {
      rf = 1;
      break;
    }
  }
  for (int i = 1; i <= m; i++) {
    ff = 0;
    for (int j = 1; j <= n; j++) {
      if (a[j][i] == 1) {
        ff = 1;
        break;
      }
    }
    if (ff == 0) {
      cf = 1;
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    ff = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == 1) {
        if (ff && a[i][j - 1] == 0) {
          f = 1;
          break;
        } else
          ff = 1;
      }
    }
    if (ff == 0) {
      if (cf == 0) {
        f = 1;
      }
    }
    if (f) break;
  }
  for (int i = 1; i <= m; i++) {
    ff = 0;
    for (int j = 1; j <= n; j++) {
      if (a[j][i] == 1) {
        if (ff && a[j - 1][i] == 0) {
          f = 1;
          break;
        } else
          ff = 1;
      }
    }
    if (ff == 0) {
      if (rf == 0) {
        f = 1;
      }
    }
    if (f) break;
  }
  if (f) {
    cout << -1 << endl;
    return 0;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (v[i][j] == 0 && a[i][j] == 1) {
        dfs(i, j);
        sum++;
      }
    }
  }
  cout << sum << endl;
  return 0;
}
