#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = (long long)1e9 + 7;
using namespace std;
template <class T>
void smin(T& a, T val) {
  if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
  if (a < val) a = val;
}
const long long N = 1e6 + 100;
long long n;
string s = "";
long long a[10];
string rem[10];
void pre() {
  long long a[] = {1, 6, 8, 9};
  do {
    string ok = "";
    long long rem = 0;
    for (long long i = 0; i < 4; ++i) {
      rem = (rem * 10) + a[i];
      char c = '0' + a[i];
      ok = ok + c;
      rem %= 7;
    }
    ::rem[rem] = ok;
  } while (next_permutation(a, a + 4));
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s;
  n = (long long)(s.size());
  for (long long i = 0; i < n; ++i) {
    a[s[i] - '0']++;
  }
  a[1]--, a[6]--, a[8]--, a[9]--;
  long long rem = 0;
  for (long long i = 1; i < 10; ++i) {
    while (a[i] > 0) {
      rem = ((rem * 10) + i) % 7;
      cout << i;
      --a[i];
    }
  }
  pre();
  long long which = (-4 * rem) % 7;
  which += 7;
  which %= 7;
  cout << ::rem[which];
  while (a[0] > 0) {
    cout << 0;
    --a[0];
  }
  return 0;
}
