import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().run(in, out);
        out.close();
    }

    public static long mod = 17352642619633L;

    int N;
    int M;
    char[][] g;

    int[] dx = {0, 0, -1, 1};
    int[] dy = {1, -1, 0, 0};

    void run(FastScanner in, PrintWriter out) {


        N = in.nextInt();
        M = in.nextInt();
        g = new char[N][];

        for (int i = 0; i < N; i++) {
            g[i] = in.next().toCharArray();
        }

        int[] rowSegs = new int[N];
        int[] colSegs = new int[M];

        // rows with no segs in them
        int goodCol = -1;
        int goodRow = -1;

        for (int i = 0; i < N; i++) {
            // need exactly one contiguous segCnt
            int segCnt = 0;
            for (int j = 0; j < M;) {
                if (g[i][j] == '.') {
                    j++;
                    continue;
                }
                segCnt++;
                while (j < M && g[i][j] == '#') j++;
            }
            rowSegs[i] = segCnt;
            if (segCnt == 0) goodRow = i;
        }

        for (int j = 0; j < M; j++) {
            // need exactly one contiguous segCnt
            int segCnt = 0;
            for (int i = 0; i < N;) {
                if (g[i][j] == '.') {
                    i++;
                    continue;
                }
                segCnt++;
                while (i < N && g[i][j] == '#') i++;
            }
            colSegs[j] = segCnt;
            if (segCnt == 0) goodCol = j;
        }

        for (int i = 0; i < N; i++) {
            if (rowSegs[i] > 1 || (rowSegs[i] == 0 && goodCol == -1)) {
                NO();
            }
        }
        for (int j = 0; j < M; j++) {
            if (colSegs[j] > 1 || (colSegs[j] == 0 && goodRow == -1)) {
                NO();
            }
        }

        // find number of connected components
        visited = new boolean[N][M];
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                if (g[i][j] == '#' && !visited[i][j]) {
                    cnt++;
                    dfs(i, j);
                }
            }
        }

        out.println(cnt);
    }

    boolean[][] visited;

    void dfs(int x, int y) {
        if (visited[x][y] || g[x][y] == '.') return;
        visited[x][y] = true;
        for (int i = 0; i < 4; i++) {
            int nextx = x + dx[i];
            int nexty = y + dy[i];
            if (inBounds(nextx, nexty) && g[nextx][nexty] == '#') {
                dfs(nextx, nexty);
            }
        }
    }

    void NO() {
        System.out.println("-1");
        System.exit(0);
    }

    boolean inBounds(int x, int y) {
        return x >= 0 && y >= 0 && x < N && y < M;
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}
