#include <bits/stdc++.h>
const int dx[] = {0, -1, 0, 1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int OO = 0x3f3f3f3f, N = 100000 + 5, mod = 1e9 + 7;
using namespace std;
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
string s, ans;
int dp[100004][4][2];
int solve(int i, int rem, bool ok) {
  if (i == (int)s.size()) {
    if (!rem && ok) return 0;
    return OO;
  }
  int &ret = dp[i][rem][ok];
  if (~ret) return ret;
  ret = OO;
  int a = solve(i + 1, rem, ok) + 1;
  int b;
  if (ok) {
    b = solve(i + 1, (rem + (s[i] - '0')) % 3, 1);
  } else {
    if (s[i] != '0')
      b = solve(i + 1, (rem + (s[i] - '0')) % 3, 1);
    else
      b = solve(i + 1, (rem + (s[i] - '0')) % 3, 0) + 1;
  }
  ret = min(ret, a);
  ret = min(ret, b);
  return ret;
}
void print(int i, int rem, bool ok) {
  if (i == (int)s.size()) {
    return;
  }
  int ret = solve(i, rem, ok);
  if (ret == solve(i + 1, rem, ok) + 1) {
    print(i + 1, rem, ok);
    return;
  }
  int b;
  if (ok) {
    if (ret == solve(i + 1, (rem + (s[i] - '0')) % 3, 1)) {
      ans += s[i];
      print(i + 1, (rem + (s[i] - '0')) % 3, 1);
      return;
    }
  } else {
    if (s[i] != '0') {
      if (ret == solve(i + 1, (rem + (s[i] - '0')) % 3, 1)) {
        ans += s[i];
        print(i + 1, (rem + (s[i] - '0')) % 3, 1);
        return;
      }
    } else {
      if (ret == solve(i + 1, (rem + (s[i] - '0')) % 3, 0) + 1) {
        print(i + 1, (rem + (s[i] - '0')) % 3, 1);
        return;
      }
    }
  }
}
int main() {
  run();
  cin >> s;
  memset(dp, -1, sizeof(dp));
  if (solve(0, 0, 0) == OO) {
    if (s.find("0") != string ::npos) return cout << 0, 0;
    ;
    return cout << -1, 0;
    ;
  }
  print(0, 0, 0);
  cout << ans << '\n';
}
