#include <bits/stdc++.h>
using namespace std;
string s;
string solve(long long rem) {
  long long ori_len = s.size();
  int x = 3 - rem;
  int y = (x == 1 ? 2 : 1);
  int ind1 = -1, ind2 = -1;
  string s1, s2, t1, t2;
  s1 = s2 = t1 = t2 = "";
  int cnt = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (((s[i] - '0') % 3) == y) {
      ind1 = i;
      break;
    }
  }
  int i = 0;
  if (ind1 != -1) {
    for (int j = 0; j < ori_len; j++) {
      if (j == ind1)
        continue;
      else
        s1 += s[j];
    }
    while (s1[i] == '0') i++, cnt++;
    if (i == s1.size() and cnt > 0) t1 += '0';
    for (int j = i; j < s1.size(); j++) t1 += s1[j];
  }
  ind1 = -1;
  for (i = s.size() - 1; i >= 0; i--) {
    if (((s[i] - '0') % 3) == x) {
      if (ind1 == -1)
        ind1 = i;
      else if (ind2 == -1) {
        ind2 = i;
        break;
      }
    }
  }
  if (ind1 != -1 and ind2 != -1) {
    for (int j = 0; j < ori_len; j++) {
      if (j == ind1 or j == ind2)
        continue;
      else
        s2 += s[j];
    }
    i = cnt = 0;
    while (s2[i] == '0') i++, cnt++;
    if (i == s2.size() and cnt > 0) t2 += '0';
    for (int j = i; j < s2.size(); j++) t2 += s2[j];
  }
  cerr << t1 << "              " << t2 << "\n";
  if (t1 == "" and t2 == "")
    return "-1";
  else if (t1 == "")
    return t2;
  else if (t2 == "")
    return t1;
  else
    return (t1.size() < t2.size() ? t2 : t1);
}
int main() {
  cin >> s;
  long long rem = 0;
  for (int i = 0; i < s.size(); i++) rem = (rem + int(s[i] - '0')) % 3;
  if (!rem)
    cout << s << "\n";
  else
    cout << solve(rem) << "\n";
  return 0;
}
