#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
#include<unordered_set>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
	while(true) {
		string s;
		cin >> s;
		if(s == "#") break;

		int left = -1, right = -1, ret = 0, tmp = 0;
		bool isleft = false;
		left = s[0] - '0' - 1;
		FOR(i, 1, s.size()) {
			if(isleft) {
				//?¬?????????????????????¨?????????????¶???????????????????
				if((s[i]-'0'-1)%3 > right%3) {
					right = s[i] - '0' - 1;
					tmp++;
				} else {
					left = s[i] - '0' - 1;
					isleft = false;
				}
			} else {
				if((s[i]-'0'-1)%3 < left%3) {
					left = s[i] - '0' - 1;
					tmp++;
				} else {
					right = s[i] - '0' - 1;
					isleft = true;
				}
			}
		}
		ret = tmp;
		tmp = 0;
		isleft = true;
		right = s[0] - '0' - 1;
		FOR(i, 1, s.size()) {
			if(isleft) {
				//?¬?????????????????????¨?????????????¶???????????????????
				if((s[i]-'0'-1)%3 > right%3) {
					right = s[i] - '0' - 1;
					tmp++;
				} else {
					left = s[i] - '0' - 1;
					isleft = false;
				}
			} else {
				if((s[i]-'0'-1)%3 < left%3) {
					left = s[i] - '0' - 1;
					tmp++;
				} else {
					right = s[i] - '0' - 1;
					isleft = true;
				}
			}
		}
		cout << min(ret, tmp) << endl;
	}

	return 0;
}