A = gets.chomp B = gets.chomp h = { 'N' => 0, 'E' => 1, 'S' => 2, 'W' => 3, } v1 = h[A] v2 = h[B] if v1 <= v2 puts v2 - v1 else puts 4 + v2 - v1 end