import java.util.*;
import java.io.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException,InterruptedException{
        Scanner sc = new Scanner(System.in);
        n=sc.nextInt();
        m=sc.nextInt();
        grid=new char[n][m];
        visited=new boolean[n][m];
        for (int i = 0; i < n; i++) {
			grid[i]=sc.next().toCharArray();
		}
        boolean f=true;
        int row=0,col=0;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (grid[i][j]=='#') break;
					if (j==m-1) row++;
				}
			}
	        for (int i = 0; i < m; i++) {
				for (int j = 0; j < n; j++) {
					if (grid[j][i]=='#') break;
					if (j==n-1) col++;
				}
			}
	        for (int i = 0; i < n; i++) {
	        	int chk=0;
				for (int j = 0; j < m; j++) {
					if (grid[i][j]=='#'&&chk==0) chk=1;
					if(grid[i][j]=='.'&&chk==1) chk=2; 
					if (grid[i][j]=='#'&&chk==2) f=false;
				}
			}
	        for (int i = 0; i < m; i++) {
				int chk=0;
	        	for (int j = 0; j < n; j++) {
					if (grid[j][i]=='#'&&chk==0) chk=1;
					if(grid[j][i]=='.'&&chk==1) chk=2; 
					if (grid[j][i]=='#'&&chk==2) f=false;
				}
			}
	        if (col!=0^row!=0) {
				pw.println(-1);
			}else {
				if (f) {
		        	int c=0;
		        	for (int i = 0; i < n; i++) {
		    			for (int j = 0; j < m; j++) {
		    				if(!visited[i][j]&&grid[i][j]=='#') {
		    					dfs(i,j);
		    					c++;
		    				}
		    			}
		    		}
		        	pw.println(c);
		        }else {
					pw.println(-1);
				}	
			}
	        
        pw.close();
    }
	
	static PrintWriter pw=new PrintWriter(System.out);
	static char[][] grid;
	static boolean[][] visited;
	static int n,m;
	static boolean binarysearch(long[] arr,long x) {
		int start=0,end=arr.length-1;
		while (start<=end) {
			int mid=(start+end)/2;
			if (arr[mid]==x) {
				return true;
			}else if (arr[mid]>x) {
				end=mid-1;
			}else {
				start=mid+1;
			}
		}
		return false;
	}
	static long gcd(int x,int y) {
		while (x!=y) {
			if(x>y) x-=y;
			else if(x<y) y-=x;
		}
		return x;
	}
	static long lcm(int x,int y) {
		return x*y/gcd(x,y);
	}
	static int[] dx = {1, -1, 0, 0};
	static int[] dy = {0, 0, 1, -1};
	static boolean isValid(int i, int j){
		return i >= 0 && i < n && j >= 0 && j < m && grid[i][j]=='#';
	}
	static void dfs(int x, int y){
		visited[x][y] = true;
		for(int i = 0; i < 4; i++){
				if(isValid(x + dx[i], y + dy[i]) && !visited[x + dx[i]][y + dy[i]]){
					dfs(x + dx[i], y + dy[i]);
				}	
			}
	}

	static class Pair{
        int x;
        int y;
        public Pair(int x,int y){
            this.x= x;
            this.y = y;
        }
        public String toString(){
            return x+" " + y;
        }
 
    }
 	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
 
		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
	}

}