#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
 
#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
 
const int MAX = 1000 + 5;
char grid[MAX][MAX], grid_cpy[MAX][MAX];
bool line_unblocked[MAX], column_unblocked[MAX];
int n, m;

void unblock(int x, int y);

void unblock_line(int x) {
    if (line_unblocked[x]) return;
    line_unblocked[x] = true;
    fori (i, 1, m + 1) {
        if (grid[x][i] == '#') unblock(x, i);
    }
}

void unblock_column(int y) {
    if (column_unblocked[y]) return;
    column_unblocked[y] = true;
    fori (i, 1, n + 1) {
        if (grid[i][y] == '#') unblock(i, y);
    }
}

void unblock(int x, int y) { 
    unblock_line(x);
    unblock_column(y);
}

void solve() {
    cin >> n >> m;
    fori (i, 1, n + 1) fori (j, 1, m + 1) cin >> grid[i][j];

    grid[1][1] = grid[1][m] = grid[n][1] = grid[n][m] = '#';
    memcpy(grid_cpy, grid, sizeof(char) * MAX * MAX);

    int line_cost = 0;
    unblock(1, 1);
    fori (i, 1, n + 1) {
        if (!line_unblocked[i]) {
            grid[i][1] = '#';
            line_cost++;
            unblock(i, 1);
        }
    }

    memcpy(grid, grid_cpy, sizeof(char) * MAX * MAX);
    memset(line_unblocked, false, sizeof line_unblocked);
    memset(column_unblocked, false, sizeof column_unblocked);

    int column_cost = 0;
    unblock(1, 1);
    fori (i, 1, m + 1) {
        if (!column_unblocked[i]) {
            grid[1][i] = '#';
            column_cost++;
            unblock(1, i);
        }
    }

    cout << min(line_cost, column_cost) << endl;
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<char> Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  cout << fixed << setprecision(10);
  ll a,b;
  cin >> a >> b;
  if(abs(a-b)<3) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}
