#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1 << 20);
const int inf = (int)1e9 + 42;
int n;
string s;
bool has0 = 0;
void read() {
  cin >> s;
  n = s.size();
  for (char c : s)
    if (c == '0') has0 = 1;
}
int dp[MAXN][3][2];
int nxt[MAXN][3][2];
int rec(int pos, int rem, int has) {
  if (pos == n) return (rem == 0) ? 0 : inf;
  int &memo = dp[pos][rem][has];
  if (memo != -1) return memo;
  memo = 1 + rec(pos + 1, rem, has);
  if (s[pos] != '0' || (s[pos] == '0' && has))
    if (memo > rec(pos + 1, (rem + s[pos] - '0') % 3, 1))
      nxt[pos][rem][has] = 1, memo = rec(pos + 1, (rem + s[pos] - '0') % 3, 1);
  return memo;
}
void solve() {
  memset(dp, -1, sizeof(dp));
  if (rec(0, 0, 0) >= n) {
    if (!has0)
      cout << -1 << '\n';
    else
      cout << 0 << '\n';
    return;
  }
  int rem = 0, has = 0;
  for (int i = 0; i < n; i++) {
    if (nxt[i][rem][has]) {
      cout << s[i];
      has = 1;
      rem = (rem + s[i] - '0') % 3;
    }
  }
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}
