#include <bits/stdc++.h>

using namespace std;

bool ok(int x, int y)
{
    return ((x - 1) % 3 <= (y - 1) % 3);
}

int main()
{
    char s[100001];
    
    while (scanf("%s", s) && s[0] != '#'){
        int st[2] = {-1, -1}, last = 1, vio = 0;
        int st2[2] = {-1, -1}, last2 = 0, vio2 = 0;
        
        for (int i = 0; s[i]; i++){
            s[i] -= '0';
            
            if (st[last] <= 0){
                st[1 - last] = s[i];
                last = 1 - last;
            }
            else {
                if ((last & 1) ? ok(s[i], st[last]) : ok(st[last], s[i])){
                    st[1 - last] = s[i];
                    last = 1 - last;
                }
                else {
                    st[last] = s[i];
                    vio++;
                }
            }
            
            if (st2[last2] <= 0){
                st2[1 - last2] = s[i];
                last2 = 1 - last2;
            }
            else {
                if ((last2 & 1) ? ok(s[i], st2[last2]) : ok(st2[last2], s[i])){
                    st2[1 - last2] = s[i];
                    last2 = 1 - last2;
                }
                else {
                    st2[last2] = s[i];
                    vio2++;
                }
            }
        }
        
        printf("%d\n", min(vio, vio2));
    }
    
    return (0);
}