#include <bits/stdc++.h>
int s[7] = {1869, 6198, 1896, 1689, 1986, 1968, 1698};
char arr[1000010];
int count[10];
int main() {
  scanf("%s", arr);
  int len = strlen(arr);
  int i, c;
  for (i = 0; i < 10; i++) count[i] = 0;
  for (i = 0; i < len; i++) {
    count[arr[i] - '0']++;
  }
  count[1]--;
  count[6]--;
  count[8]--;
  count[9]--;
  for (i = 1; i <= 9; i++) {
    while (count[i]--) {
      c = (c * 10 + i) % 7;
      printf("%d", i);
    }
  }
  printf("%d", s[c]);
  while (count[0]--) printf("0");
  return 0;
}
