#include <bits/stdc++.h>
using namespace std;
int aa[] = {1869, 6189, 1689, 6198, 8691, 9168, 1896}, bb[10];
char s[1000005];
int main() {
  int l, ans = 0;
  scanf("%s", s);
  l = strlen(s);
  for (int i = 0; i < l; i++) bb[s[i] - '0']++;
  bb[1]--;
  bb[6]--;
  bb[8]--;
  bb[9]--;
  for (int i = 1; i < 10; i++) {
    for (int j = 0; j < bb[i]; j++) {
      ans = (ans * 10 + i) % 7;
      printf("%d", i);
    }
  }
  printf("%d", aa[(7 - ans * 10000 % 7) % 7]);
  for (int i = 0; i < bb[0]; i++) printf("0");
  return 0;
}
