#include <bits/stdc++.h>
using namespace std;
template <class T>
void printVector(T begin, T end) {
  for (auto i = begin; i != end; i++) {
    cout << *i << ' ';
  }
  cout << endl;
}
long long readLL() {
  long long x;
  cin >> x;
  return x;
}
int readInt() {
  int x;
  cin >> x;
  return x;
}
char p[1111][1111];
bool u[1111][1111];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int n, m;
void dfs(int x, int y) {
  u[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int X = x + dx[i];
    int Y = y + dy[i];
    if (X >= 0 && X < n && Y >= 0 && Y < m) {
      if (p[X][Y] == '#' && !u[X][Y]) dfs(X, Y);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  bool hor = 0;
  bool vert = 0;
  for (int i = 0; i < n; i++) {
    bool f = 0;
    for (int j = 0; j < m; j++) {
      scanf(" %c", &p[i][j]);
      if (p[i][j] == '#') f = 1;
    }
    if (!f) hor = 1;
  }
  for (int j = 0; j < m; j++) {
    bool f = 0;
    for (int i = 0; i < n; i++) {
      if (p[i][j] == '#') f = 1;
    }
    if (!f) vert = 1;
  }
  bool noAnswer = 0;
  for (int i = 0; i < n; i++) {
    int l = m, r = 0;
    for (int j = 0; j < m; j++) {
      if (p[i][j] == '#') {
        l = j;
        break;
      }
    }
    if (l == m) continue;
    for (int j = m - 1; j >= 0; j--) {
      if (p[i][j] == '#') {
        r = j;
        break;
      }
    }
    for (int j = l; j <= r; j++) {
      if (p[i][j] == '.') noAnswer = 1;
    }
  }
  for (int j = 0; j < m; j++) {
    int l = n, r = 0;
    for (int i = 0; i < n; i++) {
      if (p[i][j] == '#') {
        l = i;
        break;
      }
    }
    if (l == n) continue;
    for (int i = n - 1; i >= 0; i--) {
      if (p[i][j] == '#') {
        r = i;
        break;
      }
    }
    for (int i = l; i <= r; i++) {
      if (p[i][j] == '.') noAnswer = 1;
    }
  }
  if (noAnswer || (vert ^ hor)) {
    printf("-1\n");
    return 0;
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (p[i][j] == '#' && !u[i][j]) {
        dfs(i, j);
        res++;
      }
    }
  }
  printf("%d\n", res);
  return 0;
}
