#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string s;
        cin >> s;
        if(s == "#")
            return 0;

        int n = s.size();
        int ret[2] = {0};
        for(int i=0; i<2; ++i){
            bool left = i % 2;
            for(int j=1; j<n; ++j){
                int a = (s[j-1] - '1') % 3;
                int b = (s[j] - '1') % 3;
                if(left){
                    if(b < a)
                        ++ ret[i];
                    else
                        left = false;
                }else{
                    if(b > a)
                        ++ ret[i];
                    else
                        left = true;
                }
            }
        }

        cout << min(ret[0], ret[1]) << endl;
    }
}