def game(t, s)
  cnt = 0
  (1...s.size) do |i|
    l = s[i - 1]; r = s[i]
    l, r = r, l if t == 1
    if r % 3 == 1 && l % 3 != 1 || r % 3 == 2 && l % 3 == 0
      cnt += 1
    else t = 1 - t
    end
  end
  cnt
end

while s = gets.chomp
  break if s == '#'
  s = s.split('').map(&:to_i)
  p [game(0, s), game(1, s)].min
end