#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    string s;
    while(cin >> s, s != "#") {
        const int INF = 1000000000;
        vector <vector <int>> dp(s.size() + 1, vector <int> (2, INF));
        dp[0][0] = dp[0][1] = 0;

        //i := 0, 左足
        //     1, 右足
        rep (i, s.size()) rep (j, 2) if (dp[i][j] != INF) {
            if (i == 0) {
                dp[i + 1][0] = dp[i][j];
                dp[i + 1][1] = dp[i][j];
            }
            else {
                //natural step
                int pre = (s[i - 1] - '0') % 3, now = (s[i] - '0') % 3;
                if ((j == 0 && ((pre == 1)
                              || (pre == 2 && (now == 2 || now == 0))
                              || (pre == 0 && now == 0)))
                 || (j == 1 && ((pre == 0)
                              || (pre == 1 && now == 1)
                              || (pre == 2 && (now == 2 || now == 1))))) {
                    //cout << i << " " << j << " " << s[i - 1] - '0' << " " << s[i] - '0' << endl;
                    dp[i + 1][!j] = min(dp[i + 1][!j], dp[i][j]);
                }

                //force
                if (j == 0) dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + 1);
                if (j == 1) dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + 1);
            }

            /*
             rep (I, s.size()) {
                rep (J, 2) cout << dp[I][J] << " ";
                cout << endl;
            }
             cout << endl;
             */
        }

        /*
        rep (i, s.size()) {
            rep (j, 2) cout << dp[i][j] << " ";
            cout << endl;
        }
        */
        cout << min(dp[s.size()][0], dp[s.size()][1]) << endl;
    }
    return 0;
}
