#include <bits/stdc++.h>
using namespace std;
int main() {
  string numbers, copy1, copy2;
  cin >> numbers;
  copy1 = numbers;
  copy2 = numbers;
  long long int cnt = 0, check = 0, i = 0, cnt1, cnt2;
  for (int i = 0; i < numbers.size(); i++) cnt += numbers[i] - 48;
  cnt1 = cnt2 = cnt;
  if (cnt1 % 3 == 1)
    for (i = copy1.size() - 1; i >= 0; i--)
      if (copy1[i] == '1' || copy1[i] == '4' || copy1[i] == '7') {
        cnt1 -= (copy1[i] - 48);
        copy1.erase(copy1.begin() + i);
        break;
      }
  if (cnt2 % 3 == 1)
    for (i = copy2.size() - 1; i >= 0; i--)
      if (copy2[i] == '2' || copy2[i] == '5' || copy2[i] == '8') {
        cnt2 -= (copy2[i] - 48);
        copy2.erase(copy2.begin() + i);
        if (cnt2 % 3 == 0) break;
      }
  if (cnt1 % 3 == 2)
    for (i = copy1.size() - 1; i >= 0; i--)
      if (copy1[i] == '2' || copy1[i] == '5' || copy1[i] == '8') {
        cnt1 -= (copy1[i] - 48);
        copy1.erase(copy1.begin() + i);
        break;
      }
  if (cnt2 % 3 == 2)
    for (i = copy2.size() - 1; i >= 0; i--)
      if (copy2[i] == '1' || copy2[i] == '4' || copy2[i] == '7') {
        cnt2 -= (copy2[i] - 48);
        copy2.erase(copy2.begin() + i);
        if (cnt2 % 3 == 0) break;
      }
  while (copy1[0] == '0' && copy1.size() != 1) copy1.erase(copy1.begin());
  while (copy2[0] == '0' && copy2.size() != 1) copy2.erase(copy2.begin());
  if (cnt1 % 3 != 0 && cnt2 % 3 != 0 || (cnt1 % 3 == 0 && copy1.size() == 0) ||
      (cnt2 % 3 == 0 && copy2.size() == 0))
    cout << -1;
  else if (cnt2 % 3 == 0 && cnt1 % 3 == 0) {
    if (copy1.size() >= copy2.size())
      cout << copy1;
    else
      cout << copy2;
  } else if (cnt1 % 3 == 0)
    cout << copy1;
  else
    cout << copy2;
  return 0;
}
