#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int check(pair<int, int> foot, bool init, const vector<int> &a, int n) {
  //cout << "check" << endl;
  bool next = init;
  int res = 0;
  for(int i=0;i<n-2;++i) {
    if(next) {
      if(a[i] < foot.first) {
        //cout << i << endl;
        res++;
        foot.first = a[i];
      } else {
        foot.second = a[i];
        next = !next;
      }
    } else {
      if(foot.second < a[i]) {
        //cout << i << endl;
        res++;
        foot.second = a[i];
      } else {
        foot.first = a[i];
        next = !next;
      }
    }
    
  }
  return res;
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  vector<int> mp = {-2, -1, 0, 1, -1, 0, 1, -1, 0, 1};

  while(1) {
    string s; cin >> s;
    int n = s.size();
    if(s == "#") break;
    vector<int> a(100000);
    pair<int, int> foot;
    bool init = 0;
    for(int i=0;i<(int)(s.size());++i) {
      int tmp = mp[(int)(s[i]-'0')];
      // cout << tmp << endl;
      if(i == 0) {
        foot.first = tmp;
      } else if(i == 1) {
        foot.second = tmp;
        if(foot.first < foot.second) {
          init = 0;
        } else {
          init = 1;
        }
      } else {
        a[i-2] = tmp;
      }
    }

    if(foot.first > foot.second) {
      swap(foot.first, foot.second);
    }
    
    if(foot.first == foot.second) cout << min(check(foot, 0, a, n), check(foot, 1, a, n)) << endl;
    else cout << check(foot, init, a, n) << endl;

  }
}

