#include <bits/stdc++.h>
const int maxN = 1000000;
char in[maxN + 1];
int occ[10], instanceOfRest[7] = {8169, 8961, 8619, 6891, 8691, 9168, 8196};
int main() {
  scanf("%s", in);
  int s = std::strlen(in);
  for (int i = 0; i < s; i++) occ[in[i] - '0']++;
  occ[1]--, occ[6]--, occ[8]--, occ[9]--;
  int powerOf10 = 1, res = 0, occOfZero = occ[0];
  occ[0] = 4;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < occ[i]; j++) {
      res = (res + (i % 7) * powerOf10) % 7;
      powerOf10 = (powerOf10 * 3) % 7;
    }
  }
  for (int i = 9; i > 0; i--)
    for (int j = 0; j < occ[i]; j++) printf("%d", i);
  printf("%d", instanceOfRest[(7 - res) % 7]);
  while (occOfZero--) printf("0");
  printf("\n");
  return 0;
}
