#include <bits/stdc++.h>
using namespace std;
const int MOD = (1e9) + 7, MAXN = (1e3) + 5;
int n, m;
bool g[MAXN][MAXN];
bool f[MAXN][MAXN];
bool gg[MAXN];
bool ff[MAXN];
bool mark[MAXN][MAXN];
int ans = 0;
bool qs = true;
bool bs = true;
int con = 0, com = 0;
int X[4] = {0, 0, 1, -1};
int Y[4] = {1, -1, 0, 0};
bool ch(int x, int y) { return (x >= 0 && y >= 0 && x < m && y < n); }
void dfs(int x, int y) {
  mark[y][x] = true;
  for (int i = 0; i < 4; i++) {
    int xx = x + X[i];
    int yy = y + Y[i];
    if (ch(xx, yy) && (!mark[yy][xx])) {
      dfs(xx, yy);
    }
  }
}
void ser1() {
  for (int qq = 0; qq < n; qq++) {
    int t, s;
    bool sss = false;
    for (int i = 0; i < m; i++) {
      if (g[qq][i]) {
        t = i;
        sss = true;
        break;
      }
    }
    for (int i = m - 1; i >= 0; i--) {
      if (g[qq][i]) {
        s = i;
        break;
      }
    }
    if (!sss) {
      con++;
      continue;
    }
    if (t == s) {
      continue;
    }
    for (int i = t + 1; i < s; i++) {
      if (!g[qq][i]) {
        qs = false;
      }
    }
  }
}
void ser2() {
  for (int qq = 0; qq < m; qq++) {
    int t, s;
    bool sss = false;
    for (int i = 0; i < n; i++) {
      if (f[qq][i]) {
        t = i;
        sss = true;
        break;
      }
    }
    for (int i = n - 1; i >= 0; i--) {
      if (f[qq][i]) {
        s = i;
        break;
      }
    }
    if (!sss) {
      com++;
      continue;
    }
    if (t == s) {
      continue;
    }
    for (int i = t + 1; i < s; i++) {
      if (!f[qq][i]) {
        qs = false;
      }
    }
  }
}
void ser3() {
  bs = ((com > 0 && con > 0) || (com == 0 && con == 0));
  qs = (qs && bs);
}
int main() {
  cin >> n >> m;
  bool q = true;
  for (int qq = 0; qq < n; qq++) {
    for (int j = 0; j < m; j++) {
      char z;
      cin >> z;
      if (z == '#') {
        g[qq][j] = true;
        f[j][qq] = true;
        mark[qq][j] = false;
      } else {
        g[qq][j] = false;
        f[j][qq] = false;
        mark[qq][j] = true;
      }
    }
  }
  ser1();
  ser2();
  ser3();
  if (!qs) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!mark[i][j]) {
        ans++;
        dfs(j, i);
      }
    }
  }
  cout << ans;
}
