#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int main(){

	int left,right,l_count,r_count;
	char buf[100001],pre;

	while(true){
		scanf("%s",buf);
		if(buf[0] == '#')break;

		l_count = 0;
		left = buf[0] - '0';
		if(left % 3 != 0){
			right = 3;
		}else{
			if(left == 3){
				right = 6;
			}else{
				right = 3;
			}
		}
		pre = 'l';

		for(int i = 1; buf[i] != '\0'; i++){
			if((left%3 == 0 && (buf[i] - '0')%3 > 0) || (left%3 == 2 && (buf[i] - '0')%3 == 1)){
				if(pre == 'l')l_count++;
				left = buf[i] - '0';
				pre = 'l';
			}else if((right % 3 == 1 && (buf[i] - '0')%3 != 1) || (right % 3 == 2 && (buf[i] - '0')%3 == 0)){
				if(pre == 'r')l_count++;
				right = buf[i] - '0';
				pre = 'r';
			}else{
				if(pre == 'l'){
					right = buf[i] - '0';
					pre = 'r';
				}else{
					left = buf[i] - '0';
					pre = 'l';
				}
			}
		}

		r_count = 0;
		right = buf[0] - '0';
		if(right % 3 != 1){
			left = 1;
		}else{
			if(right == 1){
				left = 4;
			}else{
				left = 1;
			}
		}
		pre = 'r';
		for(int i = 1; buf[i] != '\0'; i++){
			if((left%3 == 0 && (buf[i] - '0')%3 > 0) || (left%3 == 2 && (buf[i] - '0')%3 == 1)){
				if(pre == 'l')r_count++;
				left = buf[i] - '0';
				pre = 'l';
			}else if((right % 3 == 1 && (buf[i] - '0')%3 != 1) || (right % 3 == 2 && (buf[i] - '0')%3 == 0)){
				if(pre == 'r')r_count++;
				right = buf[i] - '0';
				pre = 'r';
			}else{
				if(pre == 'l'){
					right = buf[i] - '0';
					pre = 'r';
				}else{
					left = buf[i] - '0';
					pre = 'l';
				}
			}
		}

		printf("%d\n",min(l_count,r_count));

	}

    return 0;
}