#include <bits/stdc++.h>
using namespace std;
char stra[200000];
char strb[200000];
char ifa[200000];
char res[200000];
char res2[200000];
int lena;
int suma;
map<int, vector<int>> mapa;
int main() {
  scanf("%s", stra);
  lena = strlen(stra);
  suma = 0;
  for (int i = 0; i < lena; i++) {
    strb[i] = (stra[i] - '0') % 3;
    mapa[strb[i]].push_back(i);
    suma += strb[i];
  }
  suma %= 3;
  if (suma == 0) {
    int i = 0;
    for (; i < lena; i++) {
      if (stra[i] != '0') {
        break;
      }
      if (i == lena - 1) {
        puts("0");
        exit(0);
      }
    }
    printf("%s\n", stra + i);
    exit(0);
  }
  if (suma == 1) {
    if (mapa[1].size() < 1 && mapa[2].size() < 2) {
      puts("-1");
      exit(0);
    }
    if (lena <= 1) {
      puts("-1");
      exit(0);
    }
    if (mapa[1].size() >= 1 && mapa[2].size() < 2) {
      int i1 = *(--mapa[1].end());
      if (i1 == 0) {
        for (i1 = 1; i1 < lena; i1++) {
          if (stra[i1] != '0') {
            break;
          }
          if (i1 == lena - 1) {
            puts("0");
            exit(0);
          }
        }
        printf("%s\n", stra + i1);
        exit(0);
      } else {
        for (int i = 0; i < lena; i++) {
          if (i != i1) {
            putchar(stra[i]);
          }
        }
        puts("");
        exit(0);
      }
    }
    if (mapa[1].size() < 1 && mapa[2].size() >= 2) {
      if (lena <= 2) {
        puts("-1");
        exit(0);
      }
      auto it1 = --mapa[2].end();
      int i1 = *it1;
      it1--;
      int i2 = *it1;
      for (int ia = 0, ib = 0; ia < lena; ia++, ib++) {
        while (ia == i1 || ia == i2) {
          ia++;
        }
        res[ib] = stra[ia];
      }
      i1 = 0;
      for (; res[i1]; i1++) {
        if (res[i1] != '0') {
          break;
        }
        if (res[i1 + 1] == 0) {
          puts("0");
          exit(0);
        }
      }
      printf("%s\n", res + i1);
      exit(0);
    }
    auto it1 = --mapa[2].end();
    int i1 = *it1;
    it1--;
    int i2 = *it1;
    for (int ia = 0, ib = 0; ia < lena; ia++, ib++) {
      while (ia == i1 || ia == i2) {
        ia++;
      }
      res[ib] = stra[ia];
    }
    i1 = 0;
    for (; res[i1]; i1++) {
      if (res[i1] != '0') {
        break;
      }
      if (res[i1 + 1] == 0) {
        puts("0");
        exit(0);
      }
    }
    char* r1 = res + i1;
    it1 = --mapa[1].end();
    i1 = *it1;
    for (int ia = 0, ib = 0; ia < lena; ia++, ib++) {
      while (ia == i1) {
        ia++;
      }
      res2[ib] = stra[ia];
    }
    i1 = 0;
    for (; res2[i1]; i1++) {
      if (res2[i1] != '0') {
        break;
      }
      if (res2[i1 + 1] == 0) {
        puts("0");
        exit(0);
      }
    }
    char* r2 = res2 + i1;
    if (strlen(r1) > strlen(r2)) {
      printf("%s\n", r1);
    } else {
      printf("%s\n", r2);
    }
    exit(0);
  }
  if (suma == 2) {
    if (mapa[2].size() < 1 && mapa[1].size() < 2) {
      puts("-1");
      exit(0);
    }
    if (lena <= 1) {
      puts("-1");
      exit(0);
    }
    if (mapa[2].size() >= 1 && mapa[1].size() < 2) {
      int i1 = *(--mapa[2].end());
      if (i1 == 0) {
        for (i1 = 1; i1 < lena; i1++) {
          if (stra[i1] != '0') {
            break;
          }
          if (i1 == lena - 1) {
            puts("0");
            exit(0);
          }
        }
        printf("%s\n", stra + i1);
        exit(0);
      } else {
        for (int i = 0; i < lena; i++) {
          if (i != i1) {
            putchar(stra[i]);
          }
        }
        puts("");
        exit(0);
      }
    }
    if (mapa[2].size() < 1 && mapa[1].size() >= 2) {
      if (lena <= 2) {
        puts("-1");
        exit(0);
      }
      auto it1 = --mapa[1].end();
      int i1 = *it1;
      it1--;
      int i2 = *it1;
      for (int ia = 0, ib = 0; ia < lena; ia++, ib++) {
        while (ia == i1 || ia == i2) {
          ia++;
        }
        res[ib] = stra[ia];
      }
      i1 = 0;
      for (; res[i1]; i1++) {
        if (res[i1] != '0') {
          break;
        }
        if (res[i1 + 1] == 0) {
          puts("0");
          exit(0);
        }
      }
      printf("%s\n", res + i1);
      exit(0);
    }
    auto it1 = --mapa[1].end();
    int i1 = *it1;
    it1--;
    int i2 = *it1;
    for (int ia = 0, ib = 0; ia < lena; ia++, ib++) {
      while (ia == i1 || ia == i2) {
        ia++;
      }
      res[ib] = stra[ia];
    }
    i1 = 0;
    for (; res[i1]; i1++) {
      if (res[i1] != '0') {
        break;
      }
      if (res[i1 + 1] == 0) {
        puts("0");
        exit(0);
      }
    }
    char* r1 = res + i1;
    it1 = --mapa[2].end();
    i1 = *it1;
    for (int ia = 0, ib = 0; ia < lena; ia++, ib++) {
      while (ia == i1) {
        ia++;
      }
      res2[ib] = stra[ia];
    }
    i1 = 0;
    for (; res2[i1]; i1++) {
      if (res2[i1] != '0') {
        break;
      }
      if (res2[i1 + 1] == 0) {
        puts("0");
        exit(0);
      }
    }
    char* r2 = res2 + i1;
    if (strlen(r1) > strlen(r2)) {
      printf("%s\n", r1);
    } else {
      printf("%s\n", r2);
    }
    exit(0);
  }
}
