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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  string n;
  cin >> n;
  int size = n.size();
  int ans = INF;
  for(int bit = 1; bit < (1<<size); bit++){
    int sum = 0;
    int cnt = 0;
    for(int i = 0; i < size; i++){
      if(bit&(1<<i)){
        sum += n[i]-'0';
        cnt ++;
      }
    }
    if(sum % 3 == 0) ans = min(ans, size - cnt);
  }
  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    string S; cin >> S;

    deque<char> dq; bool flipped = false;
    for (auto &c : S) {
        if (c == 'R') {
            flipped = !flipped;
        } else {
            if (flipped) {
                dq.push_front(c);
            } else {
                dq.push_back(c);
            }
        }
    }
    // for (auto c : dq) cout << c;
    // cout << endl;

    vector<char> ans;
    int N = dq.size();
    int j = 0;
    REP(i, 0, N) {
        // cout << "# i : " << i << ", c : " << dq[i] << endl;
        // cout << "# j : " << j << endl;
        if (j == 0) {
            // cout << "--> empty" << endl;
            if (ans.empty()) {
                ans.push_back(dq[i]);
            } else {
                ans[j] = dq[i];
            }
            j++;
        } else if (ans[j - 1] == dq[i]) {
            // cout << "--> same" << endl;
            j--;
        } else {
            // cout << "--> use" << endl;
            if ((int)ans.size() > j) {
                ans[j] = dq[i];
            } else {
                ans.push_back(dq[i]);
            }
            j++;
        }
    }

    if (flipped) {
        REP(i, 0, j) cout << ans[j - i - 1];
        cout << endl;
    } else {
        REP(i, 0, j) cout << ans[i];
        cout << endl;
    }
    return 0;
}
