#include <bits/stdc++.h>
using namespace std;
int tt[] = {1869, 1968, 1689, 6891, 8691, 8916, 1896};
int nCount[15];
char str[1000005];
int main() {
  while (scanf("%s", str) != EOF) {
    memset(nCount, 0, sizeof(nCount));
    int len = strlen(str);
    for (int i = 0; i < len; i++) nCount[str[i] - '0']++;
    nCount[1]--;
    nCount[6]--;
    nCount[8]--;
    nCount[9]--;
    int ans = 0;
    if (len - 4 == nCount[0]) {
      printf("%d", tt[0]);
      while (nCount[0]--) {
        printf("0");
      }
      puts("");
      continue;
    }
    for (int i = 9; i >= 0; i--) {
      while (nCount[i]--) {
        ans = (ans * 10 + i) % 7;
        printf("%d", i);
      }
    }
    ans = (ans * 10) % 7;
    ans = (ans * 10) % 7;
    ans = (ans * 10) % 7;
    ans = (ans * 10) % 7;
    printf("%d\n", tt[(7 - ans) % 7]);
  }
  return 0;
}
