#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long exp(long long x, long long y) {
  x %= 1000000007;
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x % 1000000007;
    x = x * x % 1000000007;
    y >>= 1;
  }
  return res;
}
long long fact(long long n) {
  long long res = 1;
  for (long long i = 2; i <= n; ++i) (res *= i) %= 1000000007;
  return res;
}
bool isprime(long long n) {
  if (n <= 1) return 0;
  for (long long i = 2; i * i <= n; ++i)
    if (n % i == 0) return 0;
  return 1;
}
pair<bool, string> check(string n, int l1, int l2) {
  string s1 = n, s2 = n;
  reverse(s1.begin(), s1.end());
  reverse(s2.begin(), s2.end());
  int c1 = 0, c2 = 0;
  for (int i = 0; i < int(n.size()); ++i) {
    if (c1 < l1 && (s1[i] - '0') % 3 == 1) {
      s1[i] = ' ';
      ++c1;
    }
    if (c2 < l2 && (s2[i] - '0') % 3 == 2) {
      s2[i] = ' ';
      ++c2;
    }
  }
  string res1, res2;
  for (auto c : s1)
    if (c != ' ') res1 += c;
  for (auto c : s2)
    if (c != ' ') res2 += c;
  while (int(res1.size()) > 1 && res1.back() == '0') res1.pop_back();
  while (int(res2.size()) > 1 && res2.back() == '0') res2.pop_back();
  reverse(res1.begin(), res1.end());
  reverse(res2.begin(), res2.end());
  if (c1 == l1 && c2 == l2 && int(res1.size()) && int(res2.size())) {
    return make_pair(true, int(res1.size()) >= int(res2.size()) ? res1 : res2);
  } else if (c1 == l1 && int(res1.size())) {
    return make_pair(true, res1);
  } else if (c2 == l2 && int(res2.size()))
    return make_pair(true, res2);
  else
    return make_pair(false, "");
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string n;
  cin >> n;
  int sum = 0;
  int cnt[3]{};
  for (auto c : n) {
    sum += c - '0';
    ++cnt[(c - '0') % 3];
  }
  if (sum % 3 == 0) {
    cout << n;
    return 0;
  }
  if (sum % 3 == 1) {
    if (check(n, 1, 2).first) {
      cout << check(n, 1, 2).second;
      return 0;
    }
  }
  if (sum % 3 == 2) {
    if (check(n, 2, 1).first) {
      cout << check(n, 2, 1).second;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
