y = {'r' => 'qwertasdfgzxcvb', 'l' => 'yuiophjklnm'}
while (n = gets.chomp) != '#'
  f, *s = n.split('')
  h = y['r'].include?(f) ? 'r' : 'l'
  c = 0
  s.each do |k|
    unless y[h].include?(k)
      h = h == 'r' ? 'l' : 'r'
      c += 1
    end
  end
  p c
end