#include <bits/stdc++.h>
const long long inf = 1e17 + 7;
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  string inp, sp = "1689";
  cin >> inp;
  vector<string> rem(7, "");
  do {
    long long num = 0;
    for (long long i = 0; i < 4; i++) num = num * 10 + sp[i] - '0';
    num %= 7;
    rem[num] = sp;
  } while (next_permutation(sp.begin(), sp.end()));
  vector<long long> cnt(10, 0);
  for (long long i = 0; i < inp.length(); i++) cnt[inp[i] - '0']++;
  cnt[1]--;
  cnt[6]--;
  cnt[8]--;
  cnt[9]--;
  long long remain = 0;
  for (long long i = 1; i < 10; i++) {
    for (long long j = 0; j < cnt[i]; j++) {
      remain *= 10;
      remain += i;
      remain %= 7;
      cout << i;
    }
  }
  remain *= 10000;
  remain %= 7;
  cout << rem[(7 - remain) % 7];
  for (long long i = 0; i < cnt[0]; i++) cout << 0;
  cout << "\n";
  return 0;
}
