h, w = gets.split.map(&:to_i)
a = [[?#] * (w + 2)] + (1..h).map { [?#] + gets.chomp.split("") + [?#] } + [[?#] * (w + 2)]

xs = ys = xp = yp = nil
soldiers = []
(1..h).each do |y|
  (1..w).each do |x|
    if a[y][x] == ?#
      next
    elsif a[y][x] == ?%
      xs, ys = x, y
    elsif a[y][x] == ?@
      xp, yp = x, y
    elsif a[y][x] == ?$
      soldiers << [x, y]
    end
    a[y][x] = ?.
  end
end

dist = { [xs, ys] => 0 }
queue = [[xs, ys]]
until queue.empty?
  x, y = queue.shift
  d = dist[[x, y]]
  [[1, 0], [-1, 0], [0, 1], [0, -1]].each do |dx, dy|
    u, v = x + dx, y + dy
    next if a[v][u] == ?# or dist[[u, v]]
    dist[[u, v]] = d + 1
    queue << [u, v]
  end
end

puts dist[[xp, yp]] < (soldiers.map {|x, y| dist[[x, y]]}.compact.min || Float::INFINITY) ? 'Yes' : 'No'

