#include using namespace std; using ll = long long; #define ALL(v) v.begin(),v.end() #define dbg(x) cerr << #x << ": " << (x) << endl; int h,w; vector s; int main() { cin >> h >> w; s.resize(h); for (int i = 0; i < h; ++i) cin >> s[i]; using pii = pair; int inf = 1e9; vector dp(h, vector(w, pii(inf,inf))); priority_queue> pq; dp[0][0] = pii(0,0); pq.push({ 0,0,0,0 }); int dx[] = {-1, 0, 1, 0, -1}; while (pq.size()) { auto [cx, cy, x, y] = pq.top(); pq.pop(); cx = -cx; cy = -cy; if (pii(cx,cy) > dp[y][x]) continue; for (int i = 0; i < 4; ++i) { int nx = x + dx[i]; int ny = y + dx[i+1]; if (!(0 <= nx && nx < w && 0 <= ny && ny < h)) continue; if (s[ny][nx]=='#') continue; int a = abs(dx[i]); int b = abs(dx[i+1]); if (pii(cx+a, cy+b) < dp[ny][nx]) { dp[ny][nx] = pii(cx+a,cy+b); pq.push({-dp[ny][nx].first, -dp[ny][nx].second, nx, ny}); } } } if (dp[h-1][w-1] == pii(inf,inf)) { cout << "No\n"; } else { cout << "Yes\n"; cout << dp[h-1][w-1].first << " " << dp[h-1][w-1].second << '\n'; } }