#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  long long int result = 1;
  while (b > 0) {
    int lastbit = (b & 1);
    if (lastbit) {
      result = (result * a);
    }
    a = (a * a);
    b = b >> 1;
  }
  return result;
}
long long int power2(long long int a, long long int b, long long int p) {
  long long int result = 1;
  while (b > 0) {
    int lastbit = (b & 1);
    if (lastbit) {
      result = (result * a) % p;
    }
    a = (a * a) % p;
    b = b >> 1;
  }
  return result % p;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<int> SieveOfEratosthenes(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  vector<int> v;
  v.push_back(0);
  for (int p = 2; p <= n; p++)
    if (prime[p]) v.push_back(p);
  return v;
}
void shortest(map<int, vector<pair<int, long long int>>> m, int src, int n,
              long long int *dist) {
  bool visited[n + 1];
  set<pair<long long int, int>> s;
  for (int i = 0; i <= n; i++) {
    dist[i] = -1;
    visited[i] = false;
  }
  s.insert(make_pair(0ll, src));
  dist[src] = 0;
  while (!s.empty()) {
    auto t = s.begin();
    long long int dis = (*t).first;
    int u = (*t).second;
    s.erase(t);
    if (visited[u]) {
      continue;
    }
    visited[u] = true;
    for (auto tt : m[u]) {
      int v = tt.first;
      long long int w = tt.second;
      if (!visited[v]) {
        if (dist[v] != -1 && dist[v] > dis + w) {
          s.erase(make_pair(dist[v], v));
          dist[v] = dis + w;
          s.insert(make_pair(dist[v], v));
        } else if (dist[v] == -1) {
          dist[v] = dis + w;
          s.insert(make_pair(dist[v], v));
        }
      }
    }
  }
}
string fun(int n, string s, int one, int val) {
  bool visited[n];
  memset(visited, 0, sizeof(visited));
  string ans = "";
  for (int i = n - 1; i >= 0; i--) {
    int t = s[i] - '0';
    t %= 3;
    if (t == val && one) {
      visited[i] = 1;
      one--;
    }
  }
  int i = 0;
  for (; i < n; i++) {
    int t = s[i] - '0';
    if (!visited[i] && t > 0) {
      break;
    }
  }
  for (; i < n; i++) {
    if (!visited[i]) ans += s[i];
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tttt = 1;
  for (int ttt = 1; ttt <= tttt; ttt++) {
    string s;
    cin >> s;
    int n = s.size();
    int one = 0, two = 0, three = 0, zero = 0;
    for (int i = 0; i < n; i++) {
      int t = s[i] - '0';
      if (t != 0) {
        t %= 3;
        if (t == 0) {
          three++;
        } else if (t == 1) {
          one++;
        } else {
          two++;
        }
      } else {
        zero++;
      }
    }
    string ans = "";
    int o = one % 3;
    int t = two % 3;
    if (o >= t) {
      o -= t;
      if (o == 1) {
        ans = fun(n, s, 1, 1);
        if (two > 1) {
          string ans1 = fun(n, s, 2, 2);
          if (ans1.size() > ans.size()) {
            ans = ans1;
          }
        }
      } else if (o == 2) {
        if (two > 0) {
          ans = fun(n, s, 1, 2);
        } else {
          ans = fun(n, s, 2, 1);
        }
      } else {
        ans = fun(n, s, 0, 1);
      }
    } else {
      t -= o;
      if (t == 1) {
        ans = fun(n, s, 1, 2);
        if (one > 1) {
          string ans1 = fun(n, s, 2, 1);
          if (ans1.size() > ans.size()) {
            ans = ans1;
          }
        }
      } else if (t == 2) {
        if (one > 0) {
          ans = fun(n, s, 1, 1);
        } else {
          ans = fun(n, s, 2, 2);
        }
      } else {
        ans = fun(n, s, 0, 2);
      }
    }
    if (ans.size() == 0) {
      if (zero) {
        ans = "0";
      } else {
        ans = "-1";
      }
    }
    cout << ans;
    cout << endl;
  }
  return 0;
}
