#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int dp[100001][2];
int x[100000];
int n;

int solve(int now, int leg) {
  if (dp[now][leg]>=0) return dp[now][leg];
  if (now==n-1) return 0;
  int res = INF;
  if (leg==0) {
    if (x[now+1] >= x[now]) 
      res = min(res, solve(now+1,1));
    res = min(res, 1+solve(now+1,0));
  } else {
    if (x[now+1] <= x[now]) 
      res = min(res, solve(now+1,0));
    res = min(res, 1+solve(now+1,1));
  }
  return dp[now][leg] = res;
}

int main() {
  string s;
  const int xx[] = {-1,0,1,-1,0,1,-1,0,1};
  while(cin>>s,s!="#") {
    n = s.size();
    REP(i,s.size()) {
      x[i] = xx[s[i]-'1'];      
    }
    memset(dp,-1,sizeof(dp));
    cout << min(solve(0,0),solve(0,1)) << endl;
  }
}