#include <bits/stdc++.h>
using namespace std;
using big = long long;
const int N = 1020;
char a[N][N];
bool vis[N][N], hasr[N], hasc[N], okr[N], okc[N];
int n, m;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
void ff(int sx, int sy) {
  queue<pair<int, int>> q;
  q.push({sx, sy});
  vis[sx][sy] = true;
  while (!q.empty()) {
    auto s = q.front();
    q.pop();
    for (int i = 0; i < 4; ++i) {
      int xx = s.first + dx[i], yy = s.second + dy[i];
      if (1 <= xx && xx <= n && 1 <= yy && yy <= m && !vis[xx][yy] &&
          a[xx][yy] == '#') {
        q.push({xx, yy});
        vis[xx][yy] = true;
      }
    }
  }
}
int solve() {
  for (int i = 1; i <= n; ++i) {
    int start = -1;
    int j;
    for (j = 1; j <= m; ++j) {
      if (a[i][j] == '#') {
        start = j;
        break;
      }
    }
    if (start != -1) {
      for (j = start; j <= m && a[i][j] == '#'; ++j) {
      }
      for (; j <= m; ++j) {
        if (a[i][j] == '#') {
          return -1;
        }
      }
    }
  }
  for (int j = 1; j <= m; ++j) {
    int start = -1;
    int i;
    for (i = 1; i <= n; ++i) {
      if (a[i][j] == '#') {
        start = i;
        break;
      }
    }
    if (start != -1) {
      for (i = start; i <= n && a[i][j] == '#'; ++i) {
      }
      for (; i <= n; ++i) {
        if (a[i][j] == '#') {
          return -1;
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (a[i][j] == '#') {
        hasr[i] = hasc[j] = true;
        okr[i] = okc[j] = true;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (!hasr[i] && !hasc[j]) {
        okr[i] = okc[j] = true;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (!okr[i]) {
      return -1;
    }
  }
  for (int j = 1; j <= m; ++j) {
    if (!okc[j]) {
      return -1;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (!vis[i][j] && a[i][j] == '#') {
        ff(i, j);
        ++cnt;
      }
    }
  }
  return cnt;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> (a[i] + 1);
  }
  cout << solve() << endl;
}
