#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long dx[] = {-1, 1, 0, 0};
long long dy[] = {0, 0, -1, 1};
long long n, m;
char a[1002][1002], vis[1002][1002];
void dfs(long long x, long long y) {
  vis[x][y] = 1;
  for (long long i = 0; i < 4; i++) {
    long long x1 = x + dx[i], y1 = y + dy[i];
    if (x1 >= 1 && x1 <= n && y1 >= 1 && y1 <= m && a[x1][y1] == '#' &&
        vis[x1][y1] == 0)
      dfs(x1, y1);
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  memset(vis, 0, sizeof(vis));
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (vis[i][j] == 0 && a[i][j] == '#') {
        dfs(i, j);
        ans++;
      }
    }
  }
  bool check = 1;
  long long cnt1 = 0, cnt2 = 0;
  for (long long i = 1; i <= n; i++) {
    long long l = -1, r = -1;
    for (long long j = 1; j <= m; j++)
      if (a[i][j] == '#') {
        l = j;
        break;
      }
    for (long long j = m; j >= 1; j--) {
      if (a[i][j] == '#') {
        r = j;
        break;
      }
    }
    if (l == -1) cnt1++;
    for (long long j = l; j <= r; j++) {
      if (a[i][j] == '.') check = 0;
    }
  }
  for (long long i = 1; i <= m; i++) {
    long long l = -1, r = -1;
    for (long long j = 1; j <= n; j++) {
      if (a[j][i] == '#') {
        l = j;
        break;
      }
    }
    for (long long j = n; j >= 1; j--) {
      if (a[j][i] == '#') {
        r = j;
        break;
      }
    }
    if (l == -1) cnt2++;
    for (long long j = l; j <= r; j++) {
      if (a[j][i] == '.') check = 0;
    }
  }
  if ((cnt2 == 0 && cnt1 != 0) || (cnt2 != 0 && cnt1 == 0)) check = 0;
  if (!check)
    cout << -1;
  else
    cout << ans;
}
