#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return (!y ? x : gcd(y, x % y)); }
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
void file() {}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  file();
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int n;
string s;
int dp[N][10][2];
int upd(int x) {
  int sum = 0;
  while (x) sum += x % 10, x /= 10;
  return sum;
}
int solve(int idx, int sum, bool ok) {
  if (idx == n) {
    if (sum % 3 == 0) return 0;
    return 1e9;
  }
  int &ret = dp[idx][sum][ok];
  if (~ret) return ret;
  ret = solve(idx + 1, sum, ok) + 1;
  if (ok || s[idx] != '0')
    ret = min(ret, solve(idx + 1, upd(sum + s[idx] - 48), 1));
  return ret;
}
void solve2(int idx, int sum, bool ok) {
  if (idx == n) {
    return;
  }
  int &ret = dp[idx][sum][ok];
  if (ret == solve(idx + 1, sum, ok) + 1) {
    solve2(idx + 1, sum, ok);
    return;
  }
  cout << s[idx];
  solve2(idx + 1, upd(sum + s[idx] - 48), 1);
  return;
}
int main() {
  fast();
  memset((dp), -1, sizeof(dp));
  cin >> s;
  n = (int)s.size();
  bool ok = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    ok |= s[i] == '0';
  }
  int x = solve(0, 0, 0);
  if (x == n) {
    if (!ok)
      cout << -1;
    else
      cout << 0;
    return 0;
  }
  solve2(0, 0, 0);
  return 0;
}
