#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N;
  cin >> N;
  int S = 0, one = 0, two = 0, len = 0;
  while(N>0){
    if((N%10)%3 == 1){
      one++;
    }else if((N%10)%3 == 2){
      two++;
    }
    S += N%10;
    N = N/10;
    len++;
  }
  if(len == 1){
    if(S%3 == 0){
      cout << "0" << endl;
    }else{
      cout << "-1" << endl;
    }
  }else if(len == 2){
    if(S%3 == 0){
      cout << "0" << endl;
    }else if(S%3 == 1){
      if(one >= 1){
        cout << "1" << endl;
      }else{
        cout << "-1" << endl;
      }
    }else{
      if(two >= 1){
        cout << "1" << endl;
      }else{
        cout << "-1" << endl;
      }
    }
  }else{
    if(S%3 == 0){
      cout << "0" << endl;
    }else if(S%3 == 1){
      if(one >= 1){
        cout << "1" << endl;
      }else if(two >= 2){
        cout << "2" << endl;
      }else{
        cout << "-1" << endl;
      }
    }else{
      if(two >= 1){
        cout << "1" << endl;
      }else if(one >= 2){
        cout << "2" << endl;
      }else{
        cout << "-1" << endl;
      }
    }
  }
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main()
{
  ll n;
  cin >> n;

  vector<int> b;
  int k = 1;
  ll m = n;
  while(m > 0){
    if(m/10 != 0){
      k++;
    }
    b.emplace_back(m%10);
    m/=10;
  }

  if(n%3==0){
    cout << 0 << endl;
    return 0;
  }

  int ans = k+1;
  for(int i=1;i<(1<<k)-1;i++){
    ll sum = 0;
    int cnt = 0;
    for(int bit=0;bit<k;bit++){
      ll div = 1;

      if((i>>bit) & 1){
        // 削除する桁数を更新
        cnt++;
      }else{
        // sumに加算
        sum = sum*10 + b[bit];
      }

      div *= 10;

    }


    if(sum%3 == 0){
      ans = min(ans,cnt);
    }
  }

  if(ans == k+1) ans = -1;
  cout << ans << endl;

}