#include <bits/stdc++.h>
using namespace std;
long long spf[10];
long long fac[10];
void sieve() {
  spf[1] = 1;
  for (long long i = 2; i < 10; i++) spf[i] = i;
  for (long long i = 4; i < 10; i += 2) spf[i] = 2;
  for (long long i = 3; i * i < 10; i++) {
    if (spf[i] == i) {
      for (long long j = i * i; j < 10; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
map<long long, long long> getfactor(long long a) {
  map<long long, long long> m;
  while (a > 1) {
    m[spf[a]]++;
    a /= spf[a];
  }
  return m;
}
long long power(long long x, long long y) {
  long long res = 1;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long inverse(long long a, long long p) { return power(a, p - 2); }
long long ncr(long long n, long long r, long long p) {
  if (r == 0) return 1;
  return (fac[n] * inverse(fac[r], p) % p * inverse(fac[n - r], p) % p) % p;
}
void solve() {
  string s;
  cin >> s;
  long long ss = s.size();
  long long a[ss];
  bool vis1[ss + 1], vis2[ss + 1];
  memset(vis1, false, sizeof(vis1));
  memset(vis2, false, sizeof(vis2));
  long long sum = 0;
  for (long long i = 0; i < ss; i++) {
    sum += s[i] - '0';
    a[i] = (s[i] - '0') % 3;
  }
  sum = sum % 3;
  if (sum == 0) {
    cout << s << '\n';
  } else if (sum == 1) {
    string s1, s2;
    long long count = 0;
    for (long long i = ss - 1; i >= 0; i--) {
      if (a[i] == 1) {
        vis1[i] = true;
        count++;
        break;
      }
    }
    if (count > 0) {
      count = 0;
      for (long long i = 0; i < ss; i++) {
        if (vis1[i] == true)
          count++;
        else if (s[i] == '0' && i == count && count >= 1) {
          count++;
          vis1[i] = true;
        } else
          s1.push_back(s[i]);
      }
      if (s1.size() == 0 && s[ss - 1] == '0' && vis1[ss - 1] == true)
        s1.push_back('0');
    }
    count = 0;
    for (long long i = ss - 1; i >= 0; i--) {
      if (a[i] == 2) {
        count++;
        vis2[i] = true;
      }
      if (count == 2) break;
    }
    if (count == 2) {
      count = 0;
      for (long long i = 0; i < ss; i++) {
        if (vis2[i] == true)
          count++;
        else if (s[i] == '0' && i == count && count >= 2) {
          count++;
          vis2[i] = true;
        } else
          s2.push_back(s[i]);
      }
      if (s2.size() == 0 && s[ss - 1] == '0' && vis2[ss - 1] == true)
        s2.push_back('0');
    }
    if (s1.size() == 0 && s2.size() == 0)
      cout << -1 << '\n';
    else if (s1.size() > s2.size()) {
      if (s1[0] == '0') {
        long long count1 = -1;
        for (long long i = 0; i < s1.size(); i++) {
          if (s1[i] != '0') {
            count1++;
            cout << s1[i];
          } else if (s1[i] == '0' && count1 >= 0)
            cout << s1[i];
        }
        if (count1 == -1) cout << 0;
        cout << '\n';
      } else
        cout << s1 << '\n';
    } else {
      if (s2[0] == '0') {
        long long count1 = -1;
        for (long long i = 0; i < s2.size(); i++) {
          if (s2[i] != '0') {
            count1++;
            cout << s2[i];
          } else if (s2[i] == '0' && count1 >= 0)
            cout << s2[i];
        }
        if (count1 == -1) cout << 0;
        cout << '\n';
      } else
        cout << s2 << '\n';
    }
  } else if (sum == 2) {
    string s1, s2;
    long long count = 0;
    for (long long i = ss - 1; i >= 0; i--) {
      if (a[i] == 2) {
        vis2[i] = true;
        count++;
        break;
      }
    }
    if (count > 0) {
      count = 0;
      for (long long i = 0; i < ss; i++) {
        if (vis2[i] == true)
          count++;
        else if (s[i] == '0' && i == count && count >= 1) {
          count++;
          vis2[i] = true;
        } else
          s2.push_back(s[i]);
      }
      if (s2.size() == 0 && s[ss - 1] == '0' && vis2[ss - 1] == true)
        s2.push_back('0');
    }
    count = 0;
    for (long long i = ss - 1; i >= 0; i--) {
      if (a[i] == 1) {
        count++;
        vis1[i] = true;
      }
      if (count == 2) break;
    }
    if (count == 2) {
      count = 0;
      for (long long i = 0; i < ss; i++) {
        if (vis1[i] == true)
          count++;
        else if (s[i] == '0' && i == count && count >= 2) {
          count++;
          vis1[i] = true;
        } else
          s1.push_back(s[i]);
      }
      if (s1.size() == 0 && s[ss - 1] == '0' && vis1[ss - 1] == true)
        s1.push_back('0');
    }
    if (s1.size() == 0 && s2.size() == 0)
      cout << -1 << '\n';
    else if (s1.size() > s2.size()) {
      if (s1[0] == '0') {
        long long count1 = -1;
        for (long long i = 0; i < s1.size(); i++) {
          if (s1[i] != '0') {
            count1++;
            cout << s1[i];
          } else if (s1[i] == '0' && count1 >= 0)
            cout << s1[i];
        }
        if (count1 == -1) cout << 0;
        cout << '\n';
      } else
        cout << s1 << '\n';
    } else {
      if (s2[0] == '0') {
        long long count1 = -1;
        for (long long i = 0; i < s2.size(); i++) {
          if (s2[i] != '0') {
            count1++;
            cout << s2[i];
          } else if (s2[i] == '0' && count1 >= 0)
            cout << s2[i];
        }
        if (count1 == -1) cout << 0;
        cout << '\n';
      } else
        cout << s2 << '\n';
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
