#include <bits/stdc++.h>
using namespace std;
int ara[1000005], timer[15];
int main() {
  char str[1000005];
  scanf("%s", str);
  int i, len = strlen(str);
  for (i = 0; i < len; i++) {
    int d = str[i] - '0';
    timer[d]++;
  }
  timer[1]--;
  timer[6]--;
  timer[8]--;
  timer[9]--;
  int mul = (10000 % 7), count = 0, rem = 0;
  for (i = 1; i <= 9; i++) {
    while (timer[i]-- > 0) {
      ara[count++] = i;
      rem = rem + (i * mul);
      mul = (10 * mul) % 7;
      rem = rem % 7;
    }
  }
  int in = 0;
  int perm[4] = {1, 6, 8, 9};
  do {
    in++;
    if (in > 24) {
      printf("0");
      return 0;
    }
    int num = perm[0] * 6 + perm[1] * 2 + perm[2] * 3 + perm[3];
    if ((num + rem) % 7 == 0) {
      for (i = count - 1; i >= 0; i--) printf("%d", ara[i]);
      for (i = 0; i < 4; i++) printf("%d", perm[i]);
      break;
    }
  } while (next_permutation(perm, perm + 4));
  while (timer[0]-- > 0) printf("0");
}
