#include <bits/stdc++.h>
using namespace std;
int f[12], sol[1000010], nrc, cif[] = {0, 1, 6, 8, 9};
void cifre(int need) {
  int i, rest, mod;
  need = (7 - need) % 7;
  while (1) {
    rest = 0;
    mod = 1;
    for (i = 1; i <= 4; ++i) {
      rest = (rest + cif[i] * mod) % 7;
      mod = (mod * 10) % 7;
    }
    if (rest == need) {
      for (i = 4; i >= 1; --i) printf("%d", cif[i]);
      break;
    }
    next_permutation(cif + 1, cif + 5);
  }
}
int main() {
  int i, rest, ok = 0, mod;
  char c;
  while (scanf("%c", &c) != EOF) {
    if (c == '\n') break;
    ++f[c - '0'];
  }
  for (i = 1; i <= 4; ++i) --f[cif[i]];
  rest = 0;
  mod = 10000 % 7;
  for (i = 1; i <= 9; ++i) {
    while (f[i]--) {
      sol[++nrc] = i;
      rest = (rest + i * mod) % 7;
      mod = (mod * 10) % 7;
    }
  }
  for (i = nrc; i >= 1; --i) printf("%d", sol[i]);
  cifre(rest);
  while (f[0]--) printf("0");
  printf("\n");
  return 0;
}
