//
// main.cpp
// C++
//
// Created by 胡平伍 on 16/3/30.
// Copyright © 2016年 胡平伍. All rights reserved.
//
//const static char * path = "/Users/pw/iOS程序代码/C++/C++/input.txt";
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
int main(int argc, const char * argv[]) {
int r, c;
while (cin >> r >> c) {
vector<string> v;
string tmp;
for (int i = 0; i < r; ++ i) {
cin >> tmp;
v.push_back(tmp);
}
int m, n; // B的位置
for (int i = 0; i < v.size(); ++ i) {
for (int j = 0; j < v[i].length(); ++ j) {
if (v[i][j] == 'B') {
m = i;
n = j;
}
}
}
queue<pair<int, int>> que;
que.push(make_pair(m, n));
pair<int, int> cur;
bool flag = false;
while (!que.empty()) {
cur = que.front();
que.pop();
int x = cur.first, y = cur.second;
// cout << "x = " << x << ", y = " << y << endl;
if (x > 0) {
if (v[x - 1][y] == '-') {
// cout << "\t" << x - 1 << ", " << y << endl;
que.push(make_pair(x - 1, y));
v[x - 1][y] = '#';
} else if (v[x - 1][y] == 'H') {
// cout << 'Y' << endl;
flag = true;
break;
}
}
if (x < r - 1) {
if (v[x + 1][y] == '-') {
// cout << "\t" << x + 1 << ", " << y << endl;
que.push(make_pair(x + 1, y));
v[x + 1][y] = '#';
} else if (v[x + 1][y] == 'H') {
// cout << 'Y' << endl;
flag = true;
break;
}
}
if (y > 0) {
if (v[x][y - 1] == '-') {
// cout << "\t" << x << ", " << y - 1 << endl;
que.push(make_pair(x, y - 1));
v[x][y - 1] = '#';
} else if (v[x][y - 1] == 'H') {
// cout << 'Y' << endl;
flag = true;
break;
}
}
if (y < c - 1) {
if (v[x][y + 1] == '-') {
// cout << "\t" << x << ", " << y + 1 << endl;
que.push(make_pair(x, y + 1));
v[x][y + 1] = '#';
} else if (v[x][y + 1] == 'H') {
// cout << 'Y' << endl;
flag = true;
break;
}
}
}
if (flag) {
cout << "Y" << endl;
} else {
cout << "N" << endl;
}
// if (que.empty() && v[cur.first][cur.second] != 'H') {
// cout << 'N' << endl;
// }
}
}