#include <bits/stdc++.h>
using namespace std;
const unsigned long long MOD = 1e9 + 7;
const int INF = (int)2e9 + 7;
const long long LINF = (long long)1e18;
const unsigned long long mod1 = 183453789;
const unsigned long long mod2 = 1234567891;
const int P1 = 337, P2 = 263;
template<typename T>
T input(){
T ans = 0, m = 1; char c = ' ';
while (!((c >= '0' && c <= '9') || c == '-')) c = getchar();
if (c == '-') m = -1, c = getchar();
while (c >= '0' && c <= '9') ans = ans * 10 + (c - '0'), c = getchar();
return ans * m;
}
string nextString(bool flag = false){
char ch; string ans = "";
do { ch = getchar(); } while(ch <= ' ');
while(1) {
ans += ch; ch = getchar();
if ( (!flag && ch <= ' ') || (flag && ch < ' ') ) break;
}
return ans;
}
char nextChar(){
char ch;
do {ch = getchar(); } while(ch <= ' ');
return ch;
}
void read(string& s){ s = nextString(); }
void read(char& c){ c = nextChar(); }
template<typename T> void read(T& a){ a = input<T>(); }
template<typename T, typename... R> void read(T& a, R&... r){ read(a); read(r...); }
map < int, int > m;
void print(){
for (int i = 9; i >= 0; -- i){
while (m[i] > 0){
m[i] --;
cout << i;
}
}
}
bool erase(int x){
if (m[x] > 0){
m[x] --;
return true;
} else return false;
}
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#else
freopen("divisible.in", "r", stdin);
freopen("divisible.out", "w", stdout);
#endif
string temp; read(temp);
int sum = 0;
for (auto i: temp){
(sum += int(i - '0')) %= 3;
m[int(i - '0')] ++;
}
if (sum == 1){
bool ok = false;
for (int i = 1; !ok && i < 10; i += 3){
ok |= erase(i);
}
if (!ok){
int cnt = 0;
for (int i = 2; cnt < 2 && i < 10; i += 3){
while (m[i] > 0 && cnt < 2){
m[i] --;
cnt ++;
}
}
}
} else
if (sum == 2){
bool ok = false;
for (int i = 2; !ok && i < 10; i += 3){
ok |= erase(i);
}
if (!ok){
int cnt = 0;
for (int i = 1; cnt < 2 && i < 10; i += 3){
while (m[i] > 0 && cnt < 2){
m[i] --;
cnt ++;
}
}
}
}
print();
}