#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(0);
  string s;
  cin >> s;
  int sum = 0;
  int n = (s).size();
  map<int, int> used;
  for (int i = 0; i < n; ++i) {
    sum += s[i] - '0';
    ++used[s[i] - '0'];
  }
  if (sum % 3 == 0) {
    std::cout << s;
    return 0;
  };
  vector<int> ck;
  for (int i = 1; i <= 9; ++i) {
    if (used[i] && i % 3) {
      ck.push_back(i);
    }
  }
  string fans = s;
  vector<int> kill1;
  for (int i = 0; i < (ck).size(); ++i) {
    if ((sum - ck[i]) % 3 == 0) {
      kill1.push_back(ck[i]);
    }
  }
  for (int i = 0; i < (kill1).size(); ++i) {
    string res = "";
    bool ck = 1;
    for (int j = n - 1; j >= 0; --j) {
      if (ck && (s[j] - '0') == kill1[i]) {
        ck = 0;
      } else {
        res += s[j];
      }
    }
    reverse((res).begin(), (res).end());
    while ((res).size() && res[0] == '0') res = res.substr(1);
    if ((fans).size() == n) fans = res;
    if ((fans).size() < (res).size()) fans = res;
  }
  vector<pair<int, int> > kill2;
  for (int i = 0; i < (ck).size(); ++i) {
    for (int j = i; j < (ck).size(); ++j) {
      bool ok = 0;
      if (i == j)
        ok = used[ck[i]] >= 2;
      else
        ok = used[ck[i]] && used[ck[j]];
      if (ok && ((sum - ck[i] - ck[j]) % 3 == 0)) {
        kill2.push_back({ck[i], ck[j]});
      }
    }
  }
  for (int i = 0; i < (kill2).size(); ++i) {
    string res = "";
    bool ck1 = 1, ck2 = 1;
    int pos1 = 0, pos2 = 0;
    for (int j = n - 1; j >= 0; --j) {
      if (ck1 && (s[j] - '0') == kill2[i].first) {
        ck1 = 0;
        pos1 = j;
        break;
      }
    }
    for (int j = n - 1; j >= 0; --j) {
      if (ck2 && (s[j] - '0') == kill2[i].second && j != pos1) {
        ck2 = 0;
        pos2 = j;
        break;
      }
    }
    for (int j = 0; j < n; ++j) {
      if (j != pos1 && j != pos2) {
        res += s[j];
      }
    }
    while ((res).size() && res[0] == '0') res = res.substr(1);
    if ((fans).size() == n) fans = res;
    if ((fans).size() < (res).size()) fans = res;
  }
  if ((fans).size() != (s).size() && (fans).size() > 0) {
    std::cout << fans;
    return 0;
  };
  if (used[0]) {
    std::cout << 0;
    return 0;
  };
  { std::cout << -1 << '\n'; };
  return 0;
}
