#include <bits/stdc++.h>
using namespace std;
int n, m;
string str[1005];
bool vis[1005][1005];
int fx[] = {-1, +1, 0, 0};
int fy[] = {0, 0, -1, +1};
bool check() {
  bool ok = true;
  for (int i = 0; i < n; i++) {
    bool taken = false;
    int runningCount = 0;
    for (int j = 0; j < m; j++) {
      if (str[i][j] == '#') {
        if (runningCount > 0)
          runningCount++;
        else if (taken == false)
          runningCount++;
        else {
          ok = false;
          break;
        }
      } else {
        if (runningCount > 0) {
          taken = true;
          runningCount = 0;
        }
      }
    }
  }
  for (int j = 0; j < m; j++) {
    bool taken = false;
    int runningCount = 0;
    for (int i = 0; i < n; i++) {
      if (str[i][j] == '#') {
        if (runningCount > 0)
          runningCount++;
        else if (taken == false)
          runningCount++;
        else {
          ok = false;
          break;
        }
      } else {
        if (runningCount > 0) {
          taken = true;
          runningCount = 0;
        }
      }
    }
  }
  if (ok == false) return ok;
  bool allDot = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (str[i][j] == '#') allDot = false;
    }
  }
  if (allDot) return ok;
  bool rowWhite = false, colWhite = false;
  for (int i = 0; i < n; i++) {
    bool seenBlack = false;
    for (int j = 0; j < m; j++) {
      if (str[i][j] == '#') seenBlack = true;
    }
    if (seenBlack == false) rowWhite = true;
  }
  for (int j = 0; j < m; j++) {
    bool seenBlack = false;
    for (int i = 0; i < n; i++) {
      if (str[i][j] == '#') seenBlack = true;
    }
    if (seenBlack == false) colWhite = true;
  }
  if (rowWhite && !colWhite) ok = false;
  if (colWhite && !rowWhite) ok = false;
  return ok;
}
void dfs(int x, int y) {
  vis[x][y] = true;
  for (int k = 0; k < 4; k++) {
    int tx = x + fx[k];
    int ty = y + fy[k];
    if (tx >= 0 && tx < n && ty >= 0 && ty < m && vis[tx][ty] == false &&
        str[tx][ty] == '#') {
      dfs(tx, ty);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) cin >> str[i];
  if (check() == false) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (str[i][j] == '#' && !vis[i][j]) {
        ++ans;
        dfs(i, j);
      }
    }
  }
  cout << ans;
}
