#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<functional>
#include<fstream>
#include<cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
#define f first
#define s second

string str;

int memo[2][3][3][100010];

int solve(int next, int left, int right, int p){
  if(p == str.size() || !isdigit(str[p])) return 0;
  if(memo[next][left][right][p] != -1)
    return memo[next][left][right][p];

  int ret = 10000000;
  int nn = next;
  int tmp = 0;
  int st = (str[p]-'1') % 3;
  int l = (next == 0 ? st : left);
  int r = (next == 1 ? st : right);
  if(next == 0){
    if(st > right){
      tmp++;
      next ^= 1;
      r = st;
    }else
      l = st;
  }else{
    if(st < left){
      tmp++;
      next ^= 1;
      l = st;
    }else
      r = st;
  }

  return memo[nn][left][right][p] = tmp + solve(next^1, l, r, p+1);
}

int main(){
  while(getline(cin, str) && str[0] != '#'){
    int ans = 100000000;
    REP(i,2) REP(j,3) REP(k,3)
      memset(memo[i][j][k],-1,sizeof(int)*(str.size()+2));
    ans = min(ans, solve(0,0,2,0));
    ans = min(ans, solve(1,0,2,0));
    cout << ans << endl;
  }
  return 0;
}