#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 100;
const long long INF = 9 * (long long)(1e18);
const long double PI = 3.14159265358979323846;
long long int modexp(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (y == 0)
    return 1;
  else if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res % p;
}
vector<long long int> is_prime(N + 1, 1);
void sieve(long long int n) {
  for (long long int i = 1; i <= n; i++) is_prime[i] = i;
  for (long long int i = 2; i * i <= n; i++) {
    if (is_prime[i] == i) {
      for (long long int j = i * i; j <= n; j += i)
        is_prime[j] = min(i, is_prime[j]);
    }
  }
}
string rem(string s, int flag) {
  reverse((s).begin(), (s).end());
  long long int n = s.length();
  long long int idx = 0;
  if (n == 0) {
    if (flag)
      return "0";
    else
      return s;
  } else {
    while (s[idx] == '0') idx++;
    if (idx == n)
      return "0";
    else
      return s.substr(idx);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  long long int n = s.length();
  long long int sum = 0;
  int flag = 0;
  for (long long int i = 0; i <= n - 1; i++) {
    sum += s[i] - '0';
    if (s[i] == '0') flag = 1;
  }
  if (sum % 3 == 0) {
    cout << s << "\n";
    return 0;
  } else {
    long long int md = sum % 3;
    int f = 0, f2 = 0;
    string s1, s2;
    for (long long int i = n - 1; i >= 0; i--) {
      int num = s[i] - '0';
      if (num % 3 != md)
        s1 += s[i];
      else {
        if (f)
          s1 += s[i];
        else
          f = 1;
      }
      if (num % 3 != 3 - md)
        s2 += s[i];
      else {
        if (f2 == 2)
          s2 += s[i];
        else
          f2++;
      }
    }
    if (f != 1) s1.clear();
    if (f2 != 2) s2.clear();
    s1 = rem(s1, flag);
    s2 = rem(s2, flag);
    long long int n1 = s1.length(), n2 = s2.length();
    if (n1 || n2) {
      if (n1 >= n2)
        cout << s1 << "\n";
      else
        cout << s2 << "\n";
    } else
      cout << "-1"
           << "\n";
  }
}
