#include <bits/stdc++.h>
using namespace std;
void check(long long md, string &s) {
  long long b[4] = {1, 6, 8, 9};
  do {
    long long j = md;
    for (long long i = 0; i < 4; i++) {
      j = j * 10 + b[i];
      j %= 7;
    }
    if (j == 0) {
      for (long long i = 0; i < 4; i++) {
        s += (b[i] + '0');
      }
      break;
    }
  } while (next_permutation(b, b + 4));
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  long long n = s.size();
  long long a[10] = {0};
  for (long long i = 0; i < n; i++) {
    a[s[i] - '0']++;
  }
  a[1]--, a[6]--, a[8]--, a[9]--;
  s = "";
  long long md = 0;
  for (long long i = 1; i < 10; i++) {
    while (a[i]) {
      s += (i + '0');
      md = md * 10 + i;
      md %= 7;
      a[i]--;
    }
  }
  check(md, s);
  while (a[0]) {
    s += '0';
    a[0]--;
  }
  cout << s;
  return 0;
}
