#include <bits/stdc++.h>
using namespace std;
int a[4] = {1, 6, 8, 9}, mod[7], freq[10];
int main() {
  string s;
  cin >> s;
  do {
    int x = a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3];
    mod[x % 7] = x;
  } while (next_permutation(a, a + 4));
  for (int i = 0; i < (int)s.size(); ++i) {
    ++freq[s[i] - '0'];
  }
  --freq[1], --freq[6], --freq[8], --freq[9];
  int rem = 0;
  for (int i = 1; i < 10; ++i) {
    while (freq[i]--) {
      cout << i;
      rem = (rem * 10 + i) % 7;
    }
  }
  int tmp = rem;
  for (int i = 0; i < 7; ++i) {
    rem = tmp;
    rem = (rem * 10 + (mod[i] / 1000) % 10) % 7;
    rem = (rem * 10 + (mod[i] / 100) % 10) % 7;
    rem = (rem * 10 + (mod[i] / 10) % 10) % 7;
    rem = (rem * 10 + (mod[i] / 1) % 10) % 7;
    if (!rem) {
      cout << mod[i];
      break;
    }
  }
  while (freq[0]--) cout << 0;
  return 0;
}
