#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int a[15];
int main() {
  scanf("%s", s + 1);
  ;
  int n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) {
    a[s[i] - '0']++;
  }
  a[1]--;
  a[6]--;
  a[8]--;
  a[9]--;
  if (a[0] == n - 4) {
    printf("1869");
    for (int i = 1; i <= n - 4; ++i) printf("0");
    printf("\n");
    return 0;
  }
  int bs = 10000 % 7, cou = 0, end = n - 4;
  for (int i = 0; i <= 9; ++i) {
    while (a[i]) {
      cou += bs * i;
      cou %= 7;
      bs *= 10;
      bs %= 7;
      a[i]--;
      s[end--] = i + '0';
    }
  }
  for (int i = 1; i <= n - 4; ++i) printf("%c", s[i]);
  if (cou == 0)
    printf("1869\n");
  else if (cou == 1)
    printf("1896\n");
  else if (cou == 2)
    printf("1986\n");
  else if (cou == 3)
    printf("1698\n");
  else if (cou == 4)
    printf("6198\n");
  else if (cou == 5)
    printf("1689\n");
  else
    printf("1968\n");
}
