use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let h = read::<usize>();
    let w = read::<usize>();
    let ss = (0..h)
        .map(|_| read::<String>().chars().collect::<Vec<_>>())
        .collect::<Vec<_>>();

    let mut ans = true;
    for i in 0..h {
        for j in 0..w {
            if ss[i][j] == '#' {
                let mut any = false;

                if i > 0 && ss[i - 1][j] == '#' {
                    any = true
                }
                if j > 0 && ss[i][j - 1] == '#' {
                    any = true
                }
                if i < h - 1 && ss[i + 1][j] == '#' {
                    any = true
                }
                if j < w - 1 && ss[i][j + 1] == '#' {
                    any = true
                }

                ans &= any
            }
        }
    }
    println!("{}", ans)
}
