#include <bits/stdc++.h>
using namespace std;
int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
char s[1000000 + 10];
int main(void) {
  while (scanf("%s", s) != EOF) {
    int num = 0;
    int len = strlen(s);
    int flag[10] = {0};
    for (int i = 0; i < len; i++) {
      if (s[i] == '0')
        flag[0]++;
      else if (s[i] == '1' && !flag[1])
        flag[1]++;
      else if (s[i] == '6' && !flag[6])
        flag[6]++;
      else if (s[i] == '8' && !flag[8])
        flag[8]++;
      else if (s[i] == '9' && !flag[9])
        flag[9]++;
      else {
        printf("%c", s[i]);
        num = num * 10 + s[i] - '0';
        num %= 7;
      }
    }
    int t;
    if (num == 0)
      t = 1869;
    else if (num == 1)
      t = 6198;
    else if (num == 2)
      t = 1896;
    else if (num == 3)
      t = 1689;
    else if (num == 4)
      t = 1986;
    else if (num == 5)
      t = 1968;
    else if (num == 6)
      t = 1698;
    printf("%d", t);
    while (flag[0]--) {
      printf("0");
    }
  }
  return 0;
}
