#include <iostream>
using namespace std;
int main(){
  string S;
  while(cin >> S, S != "#"){
    if(S.length() <= 2){
      cout << 0 << endl;
      continue;
    }
    int ans = 0;
    int f[2] = {S[0],S[1]}, m = 1;
    for(int i = 1; i < S.length(); ++i){
      if((m == 1 && (S[i]-'0'-1)%3 > (f[1-m]-1)%3)){
	++ans;
	f[1-m] = S[i] - '0';
      }else if((m == 0 && (S[i]-'0'-1)%3 < (f[1-m]-1)%3)){
	++ans;
	f[1-m] = S[i] - '0';
      }else{
	f[m] = S[i] - '0';
	m = 1-m;
      }
    }
    int t = 0;
    f[0] = S[1];
    f[1] = S[0];
    m = 0;
    for(int i = 1; i < S.length(); ++i){
      if((m == 1 && (S[i]-'0'-1)%3 > (f[1-m]-1)%3)){
	++t;
	f[1-m] = S[i] - '0';
      }else if((m == 0 && (S[i]-'0'-1)%3 < (f[1-m]-1)%3)){
	++t;
	f[1-m] = S[i] - '0';
      }else{
	f[m] = S[i] - '0';
	m = 1-m;
      }
    }
    //cout << ans << endl;
    //cout << t << endl;
    ans = min(ans,t);
    cout << ans << endl;
  }
  return 0;
}