#include <bits/stdc++.h>

using namespace std;

vector<int> v;
int dp[2][100100];

#define INF 1000000000
#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
bool init()
{
	v.clear();
	string s;
	cin >> s;
	if (s[0] == '#') return false;
	rep(i, s.length()) {
		v.push_back((s[i] - '0' + 2) % 3);
	}
	rep(i, 2) rep(j, 100100) dp[i][j] = INF;
	dp[0][0] = dp[1][0] = 0;
	return true;
}


int main()
{
    while (init()) {
		reps(i, 1, v.size()) {
			if (v[i] <= v[i-1]) {
				dp[0][i] = min(dp[0][i], dp[1][i-1]);
				dp[0][i] = min(dp[0][i], dp[0][i-1] + 1);
			}
			if (v[i] >= v[i-1]) {
				dp[1][i] = min(dp[1][i], dp[0][i-1]);
				dp[1][i] = min(dp[1][i], dp[1][i-1] + 1);
			}
		}
		cout << min(dp[0][v.size()-1], dp[1][v.size() - 1]) << endl;
    }
}

