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

using namespace std;

struct step
{
	int p;
	int migi;
	int hidari;
};

int main(void)
{
	string s;
	int ans;
	int i1;

	while(1){
		cin>>s;
		if(s=="#") break;

		vector<step> dp(s.size());

		for(i1=0;i1<s.size();i1++){
			dp[i1].p=s[i1]-48-1; //0から8までにしたい
			dp[i1].migi=0;
			dp[i1].hidari=0;
		}

		for(i1=1;i1<s.size();i1++){
			if(dp[i1-1].p%3<dp[i1].p%3){
				dp[i1].migi = min(dp[i1-1].hidari,dp[i1-1].migi+1);
				dp[i1].hidari = dp[i1-1].hidari+1;
			}
			else if(dp[i1-1].p%3==dp[i1].p%3){
				dp[i1].migi = min(dp[i1-1].hidari,dp[i1-1].migi+1);
				dp[i1].hidari = min(dp[i1-1].hidari+1,dp[i1-1].migi);
			}
			else {
				dp[i1].migi = dp[i1-1].migi+1;
				dp[i1].hidari = min(dp[i1-1].hidari+1,dp[i1-1].migi);
			}
			//cout<<dp[i1].hidari<<" "<<dp[i1].migi<<endl;
		}

		ans=min(dp[s.size()-1].migi,dp[s.size()-1].hidari);


		cout<<ans<<endl;		
	}

	return 0;
}