def game(t, s)
  cnt = 0
  r = l = s[0]
  (1...s.size).each do |i|
    t == 1 ? r = s[i] : l = s[i]
    if r % 3 == 1 && l % 3 != 1 || r % 3 == 2 && l % 3 == 0
      r, l = l, r
      t = 1 - t
      cnt += 1
    end
    t = 1 - t
  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