#include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int dp[2][2][9];

bool valid(int left, int right) {
  if (left == right) return false;
  left %= 3;
  right %= 3;
  return left <= right;
}

int main() {
  string str;
  while (true) {
    cin >> str;
    if (str == "#") break;
    rep (i, 2) rep (j, 9) {
      if (i == 0) {
	if (valid(str[0] - '1', j)) dp[0][i][j] = 0;
	else dp[0][i][j] = 1e9;
      } else {
	if (valid(j, str[0] - '1')) dp[0][i][j] = 0;
	else dp[0][i][j] = 1e9;
      }
    }
    rep (i, str.size() - 1) {
      rep (j, 2) rep (k, 9) dp[1][j][k] = 1e9;
      rep (j, 2) rep (k, 9) {
	if (j == 0) {
	  if (valid(str[i + 1] - '1', k)) dp[1][j][k] = dp[0][j][k] + 1;
	  else dp[1][j][k] = 1e9;
	  if (valid(str[i + 1] - '1', str[i] - '1')) {
	    rep (l, 9) dp[1][j][k] = min(dp[1][j][k], dp[0][j ^ 1][l]);
	  }
	} else {
	  if (valid(k, str[i + 1] - '1')) dp[1][j][k] = dp[0][j][k] + 1;
	  else dp[1][j][k] = 1e9;
	  if (valid(str[i] - '1', str[i + 1] - '1')) {
	    rep (l, 9) dp[1][j][k] = min(dp[1][j][k], dp[0][j ^ 1][l]);
	  }
	}
      }
      rep (j, 2) rep (k, 9) dp[0][j][k] = dp[1][j][k];
    }
    int res = 1e9;
    rep (i, 2) rep (j, 9) res = min(dp[0][i][j], res);
    cout << res << endl;
  }
  return 0;
}