#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int N = 1e5 + 9;
char s[N];
int mem[N][4][4], sz;
int solve(int i = 0, int sum = 0, bool valid = 0) {
  if (i == sz) {
    return (sum == 0 ? 0 : INF);
  }
  int &ret = mem[i][sum][valid];
  if (ret != -1) return ret;
  ret = INF;
  if (s[i] != '0' || valid) {
    ret = solve(i + 1, (sum + s[i] - '0') % 3, 1);
  }
  return ret = min(ret, solve(i + 1, sum, valid) + 1);
}
void PrintOutpot(int i = 0, int sum = 0, bool valid = 0) {
  if (i == sz) return;
  int temp = solve(i, sum, valid);
  if ((valid || s[i] != '0') &&
      temp == solve(i + 1, ((sum + s[i] - '0') % 3), 1)) {
    printf("%c", s[i]);
    PrintOutpot(i + 1, (sum + s[i] - '0') % 3, 1);
  } else {
    PrintOutpot(i + 1, sum, valid);
  }
}
int main() {
  scanf(" %s", s);
  memset(mem, -1, sizeof(mem));
  sz = strlen(s);
  if (solve() == sz) {
    if (string(s).find('0') == -1)
      puts("-1");
    else
      puts("0");
  } else {
    PrintOutpot();
  }
  return 0;
}
