#include <bits/stdc++.h>
using namespace std;
int a[((int)1e6 + 5)], n, zero, mod, numb[] = {1, 6, 8, 9}, k[4],
                                     perm[] = {0, 1, 2, 3};
string s;
vector<int> v;
int main() {
  cin >> s;
  n = s.size();
  for (int i = 1; i <= n; i++) a[i] = s[i - 1] - '0';
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= 3; j++)
      if (a[i] == numb[j] and !k[j]) k[j] = i;
  sort(k, k + 4);
  for (int i = 1; i <= n; i++) {
    if (i != k[0] and i != k[1] and i != k[2] and i != k[3] and a[i]) {
      v.push_back(a[i]);
      mod = (mod * 10 + a[i]) % 7;
    }
    zero += !a[i];
  }
  mod = (mod * 10000) % 7;
  do {
    if (!((mod + numb[perm[0]] * 1000 + numb[perm[1]] * 100 +
           numb[perm[2]] * 10 + numb[perm[3]]) %
          7))
      break;
  } while (next_permutation(perm, perm + 4));
  for (typeof(v.begin()) it = v.begin(); it != v.end(); it++) cout << *it;
  for (int i = 0; i <= 3; i++) cout << numb[perm[i]];
  while (zero--) cout << 0;
  cout << '\n';
  return 0;
}
