#include <bits/stdc++.h>
using namespace std;
string s;
int sum = 0;
vector<int> val[3];
int main() {
  ios::sync_with_stdio(false);
  cin >> s;
  int n = (int)s.size();
  for (int i = n - 1; i >= 0; i--) {
    sum += (s[i] - '0') % 3;
    val[(s[i] - '0') % 3].push_back(i);
  }
  sum %= 3;
  if (sum == 0)
    cout << s << endl;
  else {
    if (n == 1)
      cout << "-1" << endl;
    else if (val[sum].size() == 0) {
      if (n == 2)
        cout << "-1" << endl;
      else {
        if (val[3 - sum][1] == 0) {
          int st = 0;
          while (st < n && (s[st] == '0' || (s[st] - '0') % 3 == 3 - sum)) st++;
          if (st == n) cout << "0" << endl;
          for (int i = st; i < n; i++) {
            if (i != val[3 - sum][0]) cout << s[i];
          }
          cout << endl;
        } else {
          for (int i = 0; i < n; i++)
            if (i != val[3 - sum][0] && i != val[3 - sum][1]) cout << s[i];
          cout << endl;
        }
      }
    } else {
      if (val[sum][0] == 0 && s[1] == '0') {
        if ((int)val[3 - sum].size() >= 2) {
          for (int i = 0; i < n; i++)
            if (i != val[3 - sum][0] && i != val[3 - sum][1]) cout << s[i];
          cout << endl;
        } else {
          int st = 0;
          while (st < n && (st == val[sum][0] || s[st] == '0')) st++;
          if (st == n) cout << "0" << endl;
          for (int i = st; i < n; i++) cout << s[i];
          cout << endl;
        }
      } else {
        for (int i = 0; i < n; i++)
          if (i != val[sum][0]) cout << s[i];
        cout << endl;
      }
    }
  }
  return 0;
}
