#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &res) {
  char c;
  T flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  res *= flag;
}
int n, m;
char s[1005][1005];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int fx[1005], fy[1005];
void dfs(int x, int y) {
  s[x][y] = '.';
  for (int i = 0; i <= 3; i++) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    if (xx < 0 || yy < 0 || xx >= n || yy >= m)
      continue;
    else if (s[xx][yy] == '#')
      dfs(xx, yy);
  }
}
int slove() {
  int num = 0;
  for (int i = 0; i <= n - 1; i++) {
    for (int j = 0; j <= m - 1; j++) {
      if (s[i][j] == '#') {
        num++;
        dfs(i, j);
      }
    }
  }
  return num;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i <= n - 1; i++) cin >> s[i];
  int v = 0;
  for (int i = 0; i <= n - 1; i++) {
    for (int j = 0; j <= m - 1; j++)
      if (s[i][j] == '#') {
        if (fx[i] == 0) {
          fx[i] = 1;
          v++;
        }
        if (fy[j] == 0) {
          fy[j] = 1;
          v++;
        }
      }
  }
  if (v == 0)
    cout << 0 << endl;
  else {
    int x1 = 1, x2 = 1;
    for (int i = 0; i <= n - 1; i++) {
      int res = -1;
      for (int j = 0; j <= m - 1; j++) {
        if (s[i][j] == '#') {
          if (res == -1 || res == j - 1)
            res = j;
          else {
            cout << -1 << endl;
            return 0;
          }
        }
      }
      if (res == -1) x1 = -1;
    }
    for (int j = 0; j <= m - 1; j++) {
      int res = -1;
      for (int i = 0; i <= n - 1; i++) {
        if (s[i][j] == '#') {
          if (res == -1 || res == i - 1)
            res = i;
          else {
            cout << -1 << endl;
            return 0;
          }
        }
      }
      if (res == -1) x2 = -1;
    }
    int ans = slove();
    if (x1 * x2 != 1)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
