#include <bits/stdc++.h>
using namespace std;
int m, n;
char mp[2000][2000];
int vis[2000][2000];
int ran[2000][2000];
int r[2000];
int c[2000];
int nextx[4] = {0, 0, 1, -1};
int nexty[4] = {1, -1, 0, 0};
void dfs(int x, int y) {
  vis[x][y] = 1;
  mp[x][y] = '.';
  for (int i = 0; i < 4; i++) {
    int nx = x + nextx[i];
    int ny = y + nexty[i];
    if (nx > n || nx < 1 || ny > m || ny < 1) continue;
    if (!vis[nx][ny] && mp[nx][ny] == '#') {
      dfs(nx, ny);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", mp[i] + 1);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '#') {
        r[i]++;
        c[j]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (!r[i] && !c[j]) {
        ran[i][j] = 1;
      }
    }
  }
  int flag = 1;
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 1; j <= m; j++)
      if (ran[i][j]) cnt++;
    cnt += r[i];
    if (!cnt) {
      flag = 0;
      break;
    }
    int tot = r[i];
    for (int j = 1; j <= m; j++) {
      if (tot && tot < r[i] && mp[i][j] == '.') {
        flag = 0;
        break;
      } else if (mp[i][j] == '#') {
        tot--;
      }
    }
  }
  for (int j = 1; j <= m; j++) {
    int cnt = 0;
    for (int i = 1; i <= n; i++)
      if (ran[i][j]) cnt++;
    cnt += c[j];
    if (!cnt) {
      flag = 0;
      break;
    }
    int tot = c[j];
    for (int i = 1; i <= n; i++) {
      if (tot && tot < c[j] && mp[i][j] == '.') {
        flag = 0;
        break;
      } else if (mp[i][j] == '#')
        tot--;
    }
  }
  if (flag == 0) {
    printf("-1");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '#') {
        dfs(i, j);
        ans++;
      }
    }
  }
  printf("%lld", ans);
  return 0;
}
