#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
char s[N][N];
int tag[N], row, col;
int top[N], bottom[N];
void init();
void work();
int ca = 1;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  work();
  return 0;
}
void work() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> s[i] + 1;
  for (int i = 1; i <= n; i++) {
    int has = 0;
    int no = 1;
    for (int j = 1; j <= m; j++)
      if (s[i][j] == '#') {
        if (s[i][j - 1] == '.' && has) {
          cout << -1;
          return;
        }
        has = 1;
        no = 0;
      }
    row |= no;
  }
  for (int j = 1; j <= m; j++) {
    int has = 0;
    int no = 1;
    for (int i = 1; i <= n; i++)
      if (s[i][j] == '#') {
        if (s[i - 1][j] == '.' && has) {
          cout << -1;
          return;
        }
        has = 1;
        no = 0;
      }
    col |= no;
  }
  if (col ^ row) {
    cout << -1;
    return;
  }
  int cnt = 0;
  int T = 0, B = 0;
  int last = 0;
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++)
      if (s[i][j] == '#') {
        top[j] = i;
        break;
      }
    for (int i = n; i; i--)
      if (s[i][j] == '#') {
        bottom[j] = i;
        break;
      }
    if (!T)
      T = top[j], B = bottom[j];
    else {
      if (!top[j] || (B < top[j] || T > bottom[j])) {
        if (T) {
          for (int k = T; k <= B; k++) {
            if (tag[k]) {
              cout << -1;
              return;
            }
            tag[k] = 1;
          }
          cnt++;
        }
        T = top[j], B = bottom[j];
      } else {
        T = min(T, top[j]);
        B = max(B, bottom[j]);
      }
    }
  }
  if (T) {
    for (int i = T; i <= B; i++) {
      if (tag[i]) {
        cout << -1;
        return;
      }
      tag[i] = 1;
    }
    cnt++;
  }
  cout << cnt;
}
