#include //#include using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n) - 1; i >= 0; --i) #define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } template struct Dijkstra { private: int n; bool needRestore; struct Edge { int to; T cost; }; std::vector> g; std::vector> gR; public: const T INF = numeric_limits::max(); std::vector dp; Dijkstra() {} Dijkstra(int n, bool needRestore = false) : n(n), needRestore(needRestore) { g.resize(n); if (needRestore)gR.resize(n); } Dijkstra& operator=(const Dijkstra& obj) { this->v = obj.v; this->g = obj.g; this->dp = obj.dp; return *this; } void add_edge(int from, int to, T weight, bool twoWay = false) { g[from].push_back({ to,weight }); if (needRestore)gR[to].push_back({ from,weight }); if (twoWay) { g[to].push_back({ from,weight }); if (needRestore)gR[from].push_back({ to,weight }); } } int add_vertex() { g.push_back(std::vector()); return n++; } void build(int s) { dp.assign(n, INF); std::priority_queue, std::vector>, std::greater<>> pq; dp[s] = 0; pq.push({ dp[s], s }); while (!pq.empty()) { auto p = pq.top(); pq.pop(); T cost = p.first; int v = p.second; if (dp[v] < cost) continue; for (const auto &e : g[v]) { if (dp[e.to] > dp[v] + e.cost) { dp[e.to] = dp[v] + e.cost; pq.push({ dp[e.to], e.to }); } } } } std::vector restore(int s, int t) { // restoreのsはbuildのsと一致している必要がある std::vectorroute = { t }; while (s != t) { for (const auto & e : gR[t]) { if (dp[e.to] + e.cost == dp[t]) { t = e.to; route.push_back(t); break; } } } std::reverse(route.begin(), route.end()); return route; } T get(int t) { if (INF == dp[t])return -1; else return dp[t]; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int h, w; cin >> h >> w; vectors(h); Dijkstra dijkstra(h * w); rep(i, h)cin >> s[i]; rep(i, h)rep(j, w - 1)if ('#' != s[i][j] && '#' != s[i][j + 1]) { int u = i * w + j; int v = u + 1; dijkstra.add_edge(u, v, INF, true); } rep(i, h - 1)rep(j, w)if ('#' != s[i][j] && '#' != s[i + 1][j]) { int u = i * w + j; int v = u + w; dijkstra.add_edge(u, v, 1, true); } dijkstra.build(0); auto ans = dijkstra.get(h*w - 1); if (-1 == ans) { cout << "No" << endl; } else { cout << "Yes" << endl; cout << ans / INF << " " << ans % INF << endl; } return 0; }