#include <bits/stdc++.h>
using namespace std;
int a[15];
int idx(int a, int b, int c) { return a * 100 + b * 10 + c; }
bool chu(int a, int b) { return !((a - b) % 7); }
char s[1000080], dou[1000060];
int top;
void put(int x) {
  switch (x) {
    case 0:
      printf("1869");
      break;
    case 1:
      printf("1968");
      break;
    case 2:
      printf("1689");
      break;
    case 3:
      printf("6198");
      break;
    case 4:
      printf("1698");
      break;
    case 5:
      printf("1986");
      break;
    case 6:
      printf("1896");
      break;
  }
}
int yushu[7];
void init() {
  for (int i = 0; i < 7; i++) yushu[i] = i;
}
int main() {
  int i, j, k;
  while (~scanf("%s", s)) {
    int len = strlen(s);
    memset(a, 0, sizeof(a));
    for (i = 0; i < len; i++) a[s[i] - '0']++;
    int yu = 0;
    a[1]--;
    a[6]--;
    a[8]--;
    a[9]--;
    init();
    for (i = 0; i < len - 4; i++)
      for (j = 0; j < 7; j++) yushu[j] = (yushu[j] * 10) % 7;
    top = 0;
    for (i = 0; i < 10; i++)
      while (a[i]--) {
        dou[top++] = i + '0';
        yu = (yu * 10 + i) % 7;
      }
    dou[top] = 0;
    for (i = 0; i < 7; i++)
      if ((yushu[i] + yu) % 7 == 0) put(i);
    printf("%s\n", dou);
  }
  return 0;
}
