#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void infile() { freopen("input.in", "r", stdin); }
void outfile() { freopen("output.out", "w", stdout); }
long long int modex(long long int a, long long int b, long long int mod) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long int tmp = modex(a, b / 2, mod);
  tmp = (tmp * tmp) % mod;
  if (b & 1) tmp = (tmp * a) % mod;
  return tmp;
}
string s;
int len;
long long int memo[100005][3];
long long int dp(int id, int m) {
  if (id == len) {
    if (m == 0) return 0;
    return INT_MIN;
  }
  if (memo[id][m] != -1) return memo[id][m];
  long long int ans1, ans2;
  ans1 = 1 + dp(id + 1, (m + (s[id] - '0')) % 3);
  ans2 = dp(id + 1, m);
  return memo[id][m] = max(ans1, ans2);
}
int main() {
  cin >> s;
  len = s.length();
  memset((memo), (-1), sizeof((memo)));
  long long int ans = 0;
  for (long long int(i) = (0); (i) < (len); ++(i)) {
    if (s[i] != '0') {
      ans = max(ans, 1 + dp(i + 1, (s[i] - '0') % 3));
    }
  }
  if (ans == 0) {
    int flag = 1;
    for (long long int(i) = (0); (i) < (len); ++(i)) {
      if (s[i] == '0') {
        flag = 0;
      }
    }
    if (flag)
      cout << -1 << endl;
    else
      cout << 0 << endl;
  } else if (ans == 1) {
    int flag = 1;
    for (long long int(i) = (0); (i) < (len); ++(i)) {
      if (s[i] == '3' || s[i] == '6' || s[i] == '9') {
        flag = s[i] - '0';
        break;
      }
    }
    cout << flag << endl;
  } else {
    string res = "";
    int id, now;
    int flag = 0;
    for (long long int(j) = (0); (j) < (len); ++(j)) {
      for (long long int(k) = (0); (k) < (3); ++(k)) {
        if (memo[j][k] == ans - 1) {
          res += s[j - 1];
          id = j;
          now = k;
          flag = 1;
          break;
        }
      }
      if (flag) break;
    }
    ans -= 1;
    while (ans) {
      if (id == len - 1 ||
          (memo[id + 1][(now + (s[id] - '0')) % 3] == memo[id][now] - 1)) {
        res += s[id];
        now = (now + (s[id] - '0')) % 3;
        id++;
        ans--;
      } else {
        id++;
      }
    }
    cout << res << endl;
  }
  return 0;
}
