#include <bits/stdc++.h>
using namespace std;
const int MAX = 100009;
const int oo = (int)1e9;
string second;
int n;
int dp[MAX][3][2];
int solve(int i, int rem, int t) {
  if (i >= n) return (rem == 0 && t == 1) ? 0 : oo;
  int& r = dp[i][rem][t];
  if (r != -1) return r;
  r = 1 + solve(i + 1, rem, t);
  if (second[i] != '0' || t == 1) {
    r = min(r, solve(i + 1, (rem * 10 + second[i] - '0') % 3, 1));
  }
  return r;
}
void trace(int i, int rem, int t) {
  if (i >= n) return;
  int opt = solve(i, rem, t);
  if (opt == 1 + solve(i + 1, rem, t)) {
    trace(i + 1, rem, t);
  } else if (second[i] != '0' || t == 1) {
    cout << second[i];
    trace(i + 1, (rem * 10 + second[i] - '0') % 3, 1);
  }
}
int main() {
  cin >> second;
  n = (int)second.size();
  memset(dp, -1, sizeof dp);
  int v = solve(0, 0, 0);
  if (v < oo) {
    trace(0, 0, 0);
  } else {
    for (int i = 0; i < (int)second.size(); i++)
      if (second[i] == '0') return (cout << 0 << endl), 0;
    cout << -1 << endl;
  }
  return 0;
}
