#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

int step[2][100010];

int lr (char i, char j) {
    int ii = ((i - '0') - 1) % 3;
    int jj = ((j - '0') - 1) % 3;
    if (ii < jj) {
        return 0;
    } else if (ii == jj) {
        return 1;
    } else {
        return 2;
    }
}

int main() {
    while (1) {
        string s;
        cin >> s;
        if (s == "#") {
            break;
        }
        int len = s.size();
        for (int i = 0; i < 2; i++) {
            step[i][len - 1] = i;
            for (int j = len - 2; j >= 0; j--) {
                if (step[i][j + 1] == 0) {
                    if (lr(s[j], s[j + 1]) >= 1) {
                        step[i][j] = 1;
                    } else {
                        step[i][j] = 0;
                    }
                } else {
                    if (lr(s[j], s[j + 1]) <= 1) {
                        step[i][j] = 0;
                    } else {
                        step[i][j] = 1;
                    }
                }
            }
        }
        ll ans[2];
        for (int i = 0; i < 2; i++) {
            int num = 0;
            for (int j = 1; j < len; j++) {
                if (step[i][j] == step[i][j - 1]) {
                    num++;
                }
            }
            ans[i] = num;
        }
        cout << min(ans[0], ans[1]) << endl;
    }
}

