#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 998244353;
const int INF = 1e18;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

signed main(){
  string S;
  cin >> S;
  int N = (int)S.size();

  vector<pair<int, int>> ok;
  for (int bit = 0; bit < (1<<N); ++bit) {
    int now = 0;
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
      if (bit & (1<<i)) { // i番目のbitが立っていれば
        int A = S[i]-'0';
        now = now*10 + A;
        cnt++;
      }
    }
    if( now == 0 ) continue;
    if( now%3 == 0 ){
      ok.push_back(make_pair(N-cnt, now));
    }
  }

  if( ok.size() == 0 ){
    cout << -1 << endl;
  }else{
    sort(ok.begin(), ok.end());
    cout << ok[0].first << endl;
  }


}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(pow(2, N));
  for (int i = 0; i < pow(2, N); i++) cin >> A.at(i);

  int max1 = A.at(0), max2 = A.at(pow(2, N - 1));
  for (int i = 0; i < pow(2, N - 1); i++) {
    if (A.at(i) > max1)                 max1 = A.at(i);
    if (A.at(pow(2, N - 1) + i) > max2) max2 = A.at(pow(2, N - 1) + i);
  }

  int secondprize = min(max1, max2);

  for (int i = 0; i < pow(2, N); i++) {
    if (A.at(i) == secondprize) cout << i + 1 << endl;
  }

}

