#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000007;
const long long INFL = 1000000000000000007;
const long double INFS = 0.00000001;
const long long MOD = 1000000007;
const long double PI = 3.14159265;
const int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const int dir2[8][2] = {{1, 1},  {1, 0},  {1, -1}, {0, 1},
                        {0, -1}, {-1, 1}, {-1, 0}, {-1, -1}};
long long re() {
  long long x;
  scanf("%lld", &x);
  return x;
}
char rc() {
  char x;
  scanf("%c", &x);
  return x;
}
string rs() {
  char x[10000001];
  scanf("%s", &x);
  return string(x);
}
void pr(long long x) { printf("%lld", x); }
void prc(char x) { printf("%c", x); }
void prs(string x) { printf("%s", x.c_str()); }
void ps() { printf(" "); }
void pl() { printf("\n"); }
long long min(long long x, long long y) { return x < y ? x : y; }
long long minr(vector<long long> x) {
  long long Min = INFL;
  for (auto i : x) Min = min(Min, i);
  return Min;
}
long long max(long long x, long long y) { return x > y ? x : y; }
long long maxr(vector<long long> x) {
  long long Max = -INFL;
  for (auto i : x) Max = max(Max, i);
  return Max;
}
void ex_gcd(long long a, long long b, long long &d, long long &x,
            long long &y) {
  if (!b)
    d = a, x = 1, y = 0;
  else
    ex_gcd(b, a % b, d, y, x), y -= x * (a / b);
}
long long modinv(long long x) {
  long long ret, tr1, tr2;
  ex_gcd(x, MOD, tr1, ret, tr2);
  while (ret < 0) ret += MOD;
  return ret;
}
int n, m;
int a[1001][1001];
int place[1001][1001];
int rch[1001][1001];
bool good = true;
int ans = 0;
void wkplace() {
  int i, j;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) place[i][j] = 1;
  for (i = 1; i <= n; i++) {
    int black = 0, white = 0;
    for (j = 1; j <= m; j++) {
      if (a[i][j] == 1)
        black = 1;
      else if (black && a[i][j] == 0)
        white = 1;
      if (black && white) place[i][j] = 0;
    }
    black = 0, white = 0;
    for (j = m; j >= 1; j--) {
      if (a[i][j] == 1)
        black = 1;
      else if (black && a[i][j] == 0)
        white = 1;
      if (black && white) place[i][j] = 0;
    }
  }
  for (i = 1; i <= m; i++) {
    int black = 0, white = 0;
    for (j = 1; j <= n; j++) {
      if (a[j][i] == 1)
        black = 1;
      else if (black && a[j][i] == 0)
        white = 1;
      if (black && white) place[j][i] = 0;
    }
    black = 0, white = 0;
    for (j = n; j >= 1; j--) {
      if (a[j][i] == 1)
        black = 1;
      else if (black && a[j][i] == 0)
        white = 1;
      if (black && white) place[j][i] = 0;
    }
  }
}
void ckplace() {
  int i, j;
  for (i = 1; i <= n; i++) {
    bool exi = false;
    for (j = 1; j <= m; j++) {
      if (place[i][j]) {
        exi = true;
      }
    }
    if (!exi) good = false;
  }
  for (i = 1; i <= m; i++) {
    bool exi = false;
    for (j = 1; j <= n; j++) {
      if (place[j][i]) {
        exi = true;
      }
    }
    if (!exi) good = false;
  }
}
int inbd(int x, int y) {
  if (x <= 0 || x > n || y <= 0 || y > m) return 0;
  return 1;
}
void dfs(int x, int y) {
  int i;
  rch[x][y] = true;
  for (i = 0; i < 4; i++) {
    int xx = x + dir[i][0], yy = y + dir[i][1];
    if (inbd(xx, yy) && !rch[xx][yy] && a[xx][yy]) dfs(xx, yy);
  }
}
void wk() {
  int i, j;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (!rch[i][j] && a[i][j]) dfs(i, j), ans++;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      char c;
      cin >> c;
      if (c == '#') a[i][j] = 1;
    }
  wkplace();
  ckplace();
  wk();
  if (!good)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
