#include <bits/stdc++.h>
const int dx[] = {0, 0, -1, +1};
const int dy[] = {-1, +1, 0, 0};
int n, m;
char a[1005][1005];
int b[1005][1005], c1[1005][1005], c2[1005][1005], r1[1005][1005],
    r2[1005][1005];
inline void dfs(int x, int y) {
  if (b[x][y]) return;
  b[x][y] = 1;
  for (register int i = 0; i < 4; ++i) {
    int xx = x + dx[i], yy = y + dy[i];
    if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && a[xx][yy] == '#')
      dfs(xx, yy);
  }
}
int main() {
  int ans = 0;
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; ++i) scanf("%s", a[i] + 1);
  for (register int i = 1; i <= n; ++i) {
    for (register int j = 1; j <= m; ++j) {
      if (a[i][j] == '#' && !b[i][j]) ++ans, dfs(i, j);
      c1[i][j] = c1[i - 1][j] + (a[i][j] == '#' && a[i - 1][j] != '#');
      r1[i][j] = r1[i][j - 1] + (a[i][j] == '#' && a[i][j - 1] != '#');
    }
  }
  for (register int i = n; i >= 1; --i) {
    for (register int j = m; j >= 1; --j) {
      c2[i][j] = c2[i + 1][j] + (a[i][j] == '#' && a[i + 1][j] != '#');
      r2[i][j] = r2[i][j + 1] + (a[i][j] == '#' && a[i][j + 1] != '#');
    }
  }
  for (register int i = 1; i <= n; ++i) {
    int flag = 0;
    for (register int j = 1; j <= m; ++j) {
      if (c1[i][j] == c1[n][j] && r1[i][j] == r1[i][m] &&
          c2[i][j] == c2[1][j] && r2[i][j] == r2[i][1]) {
        flag = 1;
        break;
      }
    }
    if (!flag) {
      printf("-1\n");
      return 0;
    }
  }
  for (register int j = 1; j <= m; ++j) {
    int flag = 0;
    for (register int i = 1; i <= n; ++i) {
      if (c1[i][j] == c1[n][j] && r1[i][j] == r1[i][m] &&
          c2[i][j] == c2[1][j] && r2[i][j] == r2[i][1]) {
        flag = 1;
        break;
      }
    }
    if (!flag) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", ans);
  return 0;
}
