#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)100005;
const int INF = ~(1 << 31);
int n, k, a;
char d[MAXN];
int len;
vector<vector<long long> > del =
    vector<vector<long long> >(3, vector<long long>());
bool check(vector<long long> &a, vector<long long> &b) {
  if (!a.empty() &&
      !(*a.begin() == 0 && len > 1 && d[1] == 0 && b.size() > 1)) {
    d[*a.begin()] = -1;
    return true;
  }
  if (b.size() > 1) {
    d[*b.begin()] = -1;
    d[*(b.begin() + 1)] = -1;
    return true;
  }
  return false;
}
bool check3(vector<long long> &a3, vector<long long> &a1,
            vector<long long> &a2) {
  if (!a3.empty()) {
    if (*a3.begin() == 0 && len > 1 && d[1] == 0) {
      d[1] = -1;
      return true;
    } else {
      d[*a3.begin()] = -1;
      return true;
    }
  }
  if (a1.size() > 2) {
    d[*a1.begin()] = -1;
    d[*(a1.begin() + 1)] = -1;
    d[*(a1.begin() + 2)] = -1;
    return true;
  }
  if (a2.size() > 2) {
    d[*a2.begin()] = -1;
    d[*(a2.begin() + 1)] = -1;
    d[*(a2.begin() + 2)] = -1;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int sum = 0;
  cin.getline(d, MAXN);
  len = strlen(d);
  for (int i = 0; i < len; ++i) {
    char c = d[i] - '0';
    d[i] = c;
    del[c % 3].push_back(i);
    sum += c;
  }
  for (int i = 0; i < 3; ++i) {
    reverse(del[i].begin(), del[i].end());
  }
  if (sum == 0) {
    cout << -1;
    return 0;
  }
  if (sum % 3 == 1) {
    if (!check(del[1], del[2])) {
      cout << -1;
      return 0;
    }
  }
  if (sum % 3 == 2) {
    if (!check(del[2], del[1])) {
      cout << -1;
      return 0;
    }
  }
  int z = 0;
  int zeros = 0;
  for (; z < len; z++) {
    if (d[z] == 0) {
      zeros++;
      d[z] = -1;
    } else if (d[z] == -1) {
      continue;
    } else {
      break;
    }
  }
  if (z == len && zeros) {
    cout << 0;
    return 0;
  }
  if (z == len) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < len; ++i) {
    if (d[i] > -1) {
      cout << (int)d[i];
    }
  }
  return 0;
}
