#include <bits/stdc++.h>
const int MAXN = 1000010;
int dig[11], len, tem;
char Input[MAXN];
int out[] = {1869, 6198, 1896, 1689, 1986, 1968, 1698, 1869, 6198, 1896};
void init() {
  memset(dig, 0, sizeof(dig));
  dig[1] = dig[6] = dig[8] = dig[9] = -1;
  scanf("%s", Input);
  len = strlen(Input);
  for (int i = 0; i < len; i++) dig[Input[i] - '0']++;
  tem = 0;
  for (int i = 1; i < 10; i++)
    while (dig[i]--) printf("%d", i), tem = (10 * tem + i) % 7;
  printf("%d", out[tem]);
  while (dig[0]--) printf("0");
}
int main() {
  init();
  return 0;
}
