loop do
    s = gets.chomp
    break if s == "\#"
    dp = Array.new(s.length).map{Array.new(2,Float::INFINITY)}
    dp[0][0] = dp[0][1] = 0
    s = s.split(//).map(&:to_i)
    s.each_with_index do |c,i|
        break if i == s.length - 1
        if (c - 1) % 3 > (s[i + 1] - 1) % 3
            dp[i+1][0] = [dp[i][0] + 1, dp[i][1]].min
        elsif (c - 1) % 3 < (s[i + 1] - 1) % 3
            dp[i+1][1] = [dp[i][0], dp[i][1] + 1].min
        else
            dp[i+1][0] = [dp[i][0] + 1, dp[i][1]].min
            dp[i+1][1] = [dp[i][0], dp[i][1] + 1].min
        end
    end
    p dp[s.length - 1].min
end