#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); }
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
int main() {
  fastio();
  int tc = 1;
  while (tc--) {
    string s;
    cin >> s;
    int sum = 0;
    vector<int> o, z, t;
    int n = s.length();
    for (int i = 0; i < (s.length()); i++) {
      int x = s[i] - '0';
      sum += x;
      if (x % 3 == 0)
        z.push_back(i);
      else if (x % 3 == 1)
        o.push_back(i);
      else
        t.push_back(i);
    }
    if (sum % 3 == 0)
      cout << s;
    else if (sum % 3 == 1) {
      string uk = s;
      reverse(uk.begin(), uk.end());
      string a1 = uk, a2;
      bool f1 = 0, f2 = 0;
      if (o.size()) {
        f1 = 1;
        uk.erase(uk.begin() + n - o.back() - 1);
        while (uk.length() > 1 && uk.back() == '0') uk.pop_back();
        a2 = uk;
      }
      if (t.size() >= 2) {
        f2 = 1;
        uk = a1;
        uk.erase(uk.begin() + n - t.back() - 1);
        t.pop_back();
        uk.erase(uk.begin() + uk.length() - t.back() - 1);
        while (uk.length() > 1 && uk.back() == '0') uk.pop_back();
        a1 = uk;
      }
      reverse(a1.begin(), a1.end());
      reverse(a2.begin(), a2.end());
      if (!f1 && !f2)
        cout << -1;
      else if (f1 && f2) {
        if (a1.length() > a2.length())
          cout << a1;
        else
          cout << a2;
      } else if (f1) {
        cout << (a2.length() > 0 ? a2 : "-1");
      } else {
        cout << (a1.length() > 0 ? a1 : "-1");
      }
    } else {
      string uk = s;
      reverse(uk.begin(), uk.end());
      string a1 = uk, a2;
      bool f1 = 0, f2 = 0;
      if (t.size()) {
        f1 = 1;
        uk.erase(uk.begin() + n - t.back() - 1);
        while (uk.length() > 1 && uk.back() == '0') uk.pop_back();
        a2 = uk;
      }
      if (o.size() >= 2) {
        f2 = 1;
        uk = a1;
        uk.erase(uk.begin() + n - o.back() - 1);
        o.pop_back();
        uk.erase(uk.begin() + uk.length() - o.back() - 1);
        while (uk.length() > 1 && uk.back() == '0') uk.pop_back();
        a1 = uk;
      }
      if (a1.length()) reverse(a1.begin(), a1.end());
      if (a2.length()) reverse(a2.begin(), a2.end());
      if (!f1 && !f2)
        cout << -1;
      else if (f1 && f2) {
        if (a1.length() > a2.length())
          cout << a1;
        else
          cout << a2;
      } else if (f1) {
        cout << (a2.length() > 0 ? a2 : "-1");
      } else {
        cout << (a1.length() > 0 ? a1 : "-1");
      }
    }
  }
  return 0;
}
