#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e3 + 5, inf = 1e18;
long long int vis[N][N];
string s[N];
long long int n, m;
long long int dfs(long long int x, long long int y) {
  vis[x][y] = 1;
  if (x < n - 1 && s[x + 1][y] == '#' && !vis[x + 1][y]) {
    dfs(x + 1, y);
  }
  if (x > 0 && s[x - 1][y] == '#' && !vis[x - 1][y]) {
    dfs(x - 1, y);
  }
  if (y < m - 1 && s[x][y + 1] == '#' && !vis[x][y + 1]) {
    dfs(x, y + 1);
  }
  if (y > 0 && s[x][y - 1] == '#' && !vis[x][y - 1]) {
    dfs(x, y - 1);
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (long long int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  long long int flag = 0;
  vector<long long int> rows, cols;
  for (long long int i = 0; i < n; ++i) {
    long long int f = 0, f2 = 0;
    for (long long int j = 0; j < m; ++j) {
      if (s[i][j] == '#') {
        f2 = 1;
        if (f == 0) {
          f = 1;
        } else if (f == -1) {
          flag = 1;
        }
      } else {
        if (f == 1) {
          f = -1;
        }
      }
    }
    if (f2 == 0) rows.push_back(i);
  }
  for (long long int i = 0; i < m; ++i) {
    long long int f = 0, f2 = 0;
    for (long long int j = 0; j < n; ++j) {
      if (s[j][i] == '#') {
        f2 = 1;
        if (f == 0) {
          f = 1;
        } else if (f == -1) {
          flag = 1;
        }
      } else {
        if (f == 1) {
          f = -1;
        }
      }
    }
    if (f2 == 0) cols.push_back(i);
  }
  if (((long long int)((rows).size())) * ((long long int)((cols).size())) ==
          0 &&
      (((long long int)((rows).size())) + ((long long int)((cols).size()))) >
          0) {
    flag = 1;
  }
  if (flag == 1) {
    cout << -1 << "\n";
    return 0;
  }
  memset(vis, 0, sizeof(vis));
  long long int c = 0;
  for (long long int i = 0; i < n; ++i) {
    for (long long int j = 0; j < m; ++j) {
      if (!vis[i][j] && s[i][j] == '#') {
        dfs(i, j);
        c++;
      }
    }
  }
  cout << c << "\n";
  return 0;
}
