#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[100010], c[100010], d[100010];
  int b[10], sum, cnt[3], j, f, k;
  b[1] = 1;
  b[4] = 1;
  b[7] = 1;
  b[2] = 2;
  b[5] = 2;
  b[8] = 2;
  while (~scanf("%s", a)) {
    int i, len = strlen(a);
    sum = 0;
    memset(cnt, 0, sizeof(cnt));
    j = 0;
    k = 0;
    for (i = 0; i < len; i++) {
      sum += a[i] - '0';
      cnt[b[a[i] - '0']]++;
    }
    sum %= 3;
    if (sum == 0) {
      printf("%s\n", a);
      continue;
    } else if (sum == 1) {
      if (cnt[1] && cnt[2] >= 2) {
        j = 0;
        k = 0;
        f = 0;
        for (i = len - 1; i >= 0; i--) {
          if (b[a[i] - '0'] != 1) {
            c[j++] = a[i];
          } else {
            if (!f)
              f = 1;
            else
              c[j++] = a[i];
          }
        }
        f = 0;
        for (i = len - 1; i >= 0; i--) {
          if (b[a[i] - '0'] == 2) {
            if (f != 2)
              f++;
            else
              d[k++] = a[i];
          } else
            d[k++] = a[i];
        }
      } else if (cnt[1]) {
        j = 0;
        f = 0;
        for (i = len - 1; i >= 0; i--) {
          if (b[a[i] - '0'] != 1) {
            c[j++] = a[i];
          } else {
            if (!f)
              f = 1;
            else
              c[j++] = a[i];
          }
        }
      } else if (cnt[2] >= 2) {
        j = 0;
        f = 0;
        for (i = len - 1; i >= 0; i--) {
          if (b[a[i] - '0'] == 2) {
            if (f != 2)
              f++;
            else
              c[j++] = a[i];
          } else
            c[j++] = a[i];
        }
      } else {
        printf("-1\n");
        continue;
      }
    } else if (sum == 2) {
      if (cnt[2] && cnt[1] >= 2) {
        j = 0;
        k = 0;
        f = 0;
        for (i = len - 1; i >= 0; i--) {
          if (b[a[i] - '0'] != 2) {
            c[j++] = a[i];
          } else {
            if (!f)
              f = 1;
            else
              c[j++] = a[i];
          }
        }
        f = 0;
        for (i = len - 1; i >= 0; i--) {
          if (b[a[i] - '0'] == 1) {
            if (f != 2)
              f++;
            else
              d[k++] = a[i];
          } else
            d[k++] = a[i];
        }
      } else if (cnt[2]) {
        j = 0;
        f = 0;
        for (i = len - 1; i >= 0; i--) {
          if (b[a[i] - '0'] != 2) {
            c[j++] = a[i];
          } else {
            if (!f)
              f = 1;
            else
              c[j++] = a[i];
          }
        }
      } else if (cnt[1] >= 2) {
        j = 0;
        f = 0;
        for (i = len - 1; i >= 0; i--) {
          if (b[a[i] - '0'] == 1) {
            if (f != 2)
              f++;
            else
              c[j++] = a[i];
          } else
            c[j++] = a[i];
        }
      } else {
        printf("-1\n");
        continue;
      }
    }
    if (j && k) {
      f = 0;
      for (i = j - 1; i >= 0; i--) {
        if (c[i] == '0')
          f++;
        else
          break;
      }
      j -= f;
      f = 0;
      for (i = k - 1; i >= 0; i--) {
        if (d[i] == '0')
          f++;
        else
          break;
      }
      k -= f;
    }
    f = 0;
    if (j > k)
      for (i = j - 1; i >= 0; i--) {
        if (!f && c[i] != '0') f = 1;
        if (f) printf("%c", c[i]);
      }
    else
      for (i = k - 1; i >= 0; i--) {
        if (!f && d[i] != '0') f = 1;
        if (f) printf("%c", d[i]);
      }
    if (!j) {
      printf("-1\n");
      continue;
    }
    if (f)
      printf("\n");
    else
      printf("0\n");
  }
  return 0;
}
