#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
char c[N][N];
int n, m;
int g[4][2];
bool mrk[N][N];
bool has[N][2];
void dfs(int x, int y) {
  mrk[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int nx = x + g[i][0];
    int ny = y + g[i][1];
    if (!mrk[nx][ny] && 0 < nx && nx <= n && 0 < ny && ny <= m &&
        c[nx][ny] == '#')
      dfs(nx, ny);
  }
}
bool all[2];
int main() {
  g[0][0] = g[3][1] = -1;
  g[1][1] = g[2][0] = 1;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
      if (c[i][j] == '#') {
        has[i][0] = has[j][1] = 1;
      }
    }
  all[0] = all[1] = 1;
  for (int i = 1; i <= n; i++)
    if (!has[i][0]) all[0] = 0;
  for (int j = 1; j <= m; j++)
    if (!has[j][1]) all[1] = 0;
  for (int i = 1; i <= n; i++) {
    if (!has[i][0] && all[1]) {
      cout << -1;
      return 0;
    }
  }
  for (int j = 1; j <= m; j++) {
    if (!has[j][1] && all[0]) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    bool is1 = 0, is2 = 0;
    for (int j = 1; j <= m; j++)
      if (c[i][j] == '#') {
        is1 = 1;
        if (is2) {
          cout << -1;
          return 0;
        }
      } else if (is1)
        is2 = 1;
  }
  for (int j = 1; j <= m; j++) {
    bool is1 = 0, is2 = 0;
    for (int i = 1; i <= n; i++)
      if (c[i][j] == '#') {
        if (is2) {
          cout << -1;
          return 0;
        }
        is1 = 1;
      } else if (is1)
        is2 = 1;
  }
  int res = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (!mrk[i][j] && c[i][j] == '#') {
        dfs(i, j);
        res++;
      }
  cout << res;
  return 0;
}
