#include<iostream>
int main(){std::string s;int f,n,c,i,j;for(;std::cin>>s,s!="#";printf("%d\n",n))for(n=99999,f=j=-1;j++<1;f=c<n&&(n=c))for(c=i=0;++i<s.size();)f*(s[i-1]-1)%3<f*(s[i]-1)%3?c++:f*=-1;}