#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

int main() {
    string s;
    while (cin >> s, s != "#") {
        auto check = [&](bool lft) -> int { 
            int ans = 0;
            int FootL = -1, FootR = -1;
            bool fst = true;
            REP (i, 0, s.size()) {
                int step = s[i] - '1';
                if (lft) {
                    if (fst) FootL = step;
                    else {
                        if (step % 3 > FootR % 3) {
                            ans++;
                            FootR = step;
                            lft = !lft;
                        } else {
                            FootL = step;
                        }
                    }
                } else {
                    if (fst) FootR = step;
                    else {
                        if (FootL % 3 > step % 3) {
                            ans++;
                            FootL = step;
                            lft = !lft;
                        } else {
                            FootR = step;
                        }
                    }
                }
                lft = !lft;
                fst = false;
            }
            return ans;
        };
        cout << min(check(0), check(1)) << endl;
    }
    return 0;
}
