#include <bits/stdc++.h>
using namespace std;
vector<int> v1, v2;
char str[123455];
int len, zero = 0;
void print1(int index) {
  int ok = 0;
  for (int i = 0; i < len; i++) {
    if (i == index) continue;
    if (str[i] > '0') ok = 1;
    if (ok) cout << str[i];
  }
  if (ok == 0) {
    if (zero)
      cout << 0 << endl;
    else
      cout << -1 << endl;
  }
}
void print2(int index1, int index2) {
  int ok = 0;
  for (int i = 0; i < len; i++) {
    if (i == index1 || i == index2) continue;
    if (str[i] > '0') ok = 1;
    if (ok) cout << str[i];
  }
  if (ok == 0) {
    if (zero)
      cout << 0 << endl;
    else
      cout << -1 << endl;
  }
}
int main() {
  int i, j, sum = 0, Ok;
  cin >> str;
  len = strlen(str);
  for (i = 0; i < len; i++) {
    int x = str[i] - '0';
    sum += x;
    if (x % 3 == 1) v1.push_back(i);
    if (x % 3 == 2) v2.push_back(i);
    if (x == 0) zero = 1;
  }
  int l1 = v1.size(), l2 = v2.size();
  if (sum % 3 == 0)
    printf("%s\n", str);
  else if (sum % 3 == 1) {
    Ok = 0;
    if (l1 == 1 && v1[0] == 0) {
      int cnt = 0, j = 0;
      while (str[j + 1] == '0') {
        cnt++;
        j++;
      }
      if (cnt > 1 && l2 > 1) Ok = 1;
    }
    if (l1 > 0 && Ok == 0)
      print1(v1[l1 - 1]);
    else if (l2 > 1)
      print2(v2[l2 - 1], v2[l2 - 2]);
    else {
      if (zero)
        cout << 0 << endl;
      else
        cout << -1 << endl;
    }
  } else if (sum % 3 == 2) {
    Ok = 0;
    if (l2 == 1 && v2[0] == 0) {
      int cnt = 0, j = 0;
      while (str[j + 1] == '0') {
        cnt++;
        j++;
      }
      if (cnt > 1 && l1 > 1) Ok = 1;
    }
    if (l2 > 0 && Ok == 0)
      print1(v2[l2 - 1]);
    else if (l1 > 1)
      print2(v1[l1 - 1], v1[l1 - 2]);
    else {
      if (zero)
        cout << 0 << endl;
      else
        cout << -1 << endl;
    }
  }
  return 0;
}
