def game(t, s)
  cnt = 0
  s.each_cons(2).reduce(0){ |c, (l, r)|
    l, r = r, l if t == 1
    if r % 3 == 1 && l % 3 != 1 || r % 3 == 2 && l % 3 == 0
      c + 1
    else
      t = 1 - t
      c
    end
  }
end

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