#include<iostream>
using namespace std;

#define LEFT 0
#define RIGHT 1

int main()
{
  string s;
  int step,num,cnt;
  while(cin>>s,s!="#"){
    for(int i=0;i<s.size();i++)s[i]-='1';
    cnt=0;
    step=LEFT;
    for(int i=1;i<s.size();i++){
      if( step==RIGHT && (s[i-1]%3 < s[i]%3) ){cnt++;step^=1;}
      else if( step==LEFT && (s[i-1]%3 > s[i]%3) ){cnt++;step^=1;}
      step^=1;
    }
    num=cnt;
    cnt=0;
    step=RIGHT;
    for(int i=1;i<s.size();i++){
      if( step==RIGHT && (s[i-1]%3 < s[i]%3) ){cnt++;step^=1;}
      else if( step==LEFT && (s[i-1]%3 > s[i]%3) ){cnt++;step^=1;}
      step^=1;
    }
    if(cnt<num)num=cnt;
    cout<<num<<endl;
  }
}