#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
long long kai(long long x, long long y) {
  long long res = 1;
  for (long long i = x - y + 1; i <= x; i++) {
    res *= i;
    res %= 1000000007;
  }
  return res;
}
long long mod_pow(long long x, long long y, long long m) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) {
      res = res * x % m;
    }
    x = x * x % m;
    y >>= 1;
  }
  return res;
}
long long comb(long long x, long long y) {
  if (y > x) return 0;
  return kai(x, y) * mod_pow(kai(y, y), 1000000007 - 2, 1000000007) %
         1000000007;
}
long long n, m;
char a[1010][1010];
long long cum[1010][1010];
bool bl[1010][1010];
long long dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
long long ans;
void bfs(long long x, long long y) {
  bl[x][y] = true;
  queue<pair<long long, long long> > que;
  que.push(make_pair(x, y));
  while (!que.empty()) {
    long long sx = que.front().first, sy = que.front().second;
    que.pop();
    for (long long i = 0; i < 4; i++) {
      long long tx = sx + dx[i], ty = sy + dy[i];
      if (tx < 1 || n < tx || ty < 1 || m < ty || bl[tx][ty] ||
          a[tx][ty] == '.')
        continue;
      bl[tx][ty] = true;
      que.push(make_pair(tx, ty));
    }
  }
  ans++;
}
signed main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) cin >> a[i][j];
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j < m; j++) {
      if (a[i][j] == '#' && a[i][j + 1] == '.') {
        cum[i][j + 1]++;
        cum[i + 1][j + 1]--;
      }
      if (a[i][j] == '.' && a[i][j + 1] == '#') {
        cum[i][1]++;
        cum[i][j + 1]--;
        cum[i + 1][1]--;
        cum[i + 1][j + 1]++;
      }
    }
  for (long long i = 1; i < n; i++)
    for (long long j = 1; j <= m; j++) {
      if (a[i][j] == '#' && a[i + 1][j] == '.') {
        cum[i + 1][j]++;
        cum[i + 1][j + 1]--;
      }
      if (a[i][j] == '.' && a[i + 1][j] == '#') {
        cum[1][j]++;
        cum[i + 1][j]--;
        cum[1][j + 1]--;
        cum[i + 1][j + 1]++;
      }
    }
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++)
      cum[i][j] += cum[i - 1][j] + cum[i][j - 1] - cum[i - 1][j - 1];
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (!cum[i][j]) break;
      if (j == m) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (long long i = 1; i <= m; i++) {
    for (long long j = 1; j <= n; j++) {
      if (!cum[j][i]) break;
      if (j == n) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++)
      if (a[i][j] == '#' && !bl[i][j]) bfs(i, j);
  cout << ans << endl;
}
