#include <bits/stdc++.h>
using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX(1LL << 60);
const ll MOD(1000000007);
using namespace std;
using Grid = vector<vector<char>>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h, w;
  cin >> h >> w;
  Grid g(h);
  char buf;
  for (ll i = (0); i < (h); i++) {
    for (ll j = (0); j < (w); j++) cin >> buf, g[i].push_back(buf);
  }
  bool ans(true);
  for (ll i = (1); i < (h - 1); i++) {
    for (ll j = (1); j < (w - 1); j++) {
      if (g[i][j] == '#') {
        bool p(false);
        p = (g[i + 1][j] == '#') || (g[i - 1][j] == '#') ||
            (g[i][j - 1] == '#') || (g[i][j + 1] == '#');
        ans &= p;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
