#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 5;
char ch[maxn], s[maxn];
int k;
int main() {
  while (~scanf("%s", ch)) {
    int l = strlen(ch);
    int z = 0;
    k = 0;
    for (int i = 0; i < l; i++)
      if (ch[i] == '0') z++;
    int temp1 = 0, temp6 = 0, temp8 = 0, temp9 = 0;
    for (int i = 0; i < l; i++) {
      if (ch[i] == '0') continue;
      if (ch[i] == '1' && temp1 == 0) {
        temp1 = 1;
        continue;
      }
      if (ch[i] == '6' && temp6 == 0) {
        temp6 = 1;
        continue;
      }
      if (ch[i] == '8' && temp8 == 0) {
        temp8 = 1;
        continue;
      }
      if (ch[i] == '9' && temp9 == 0) {
        temp9 = 1;
        continue;
      }
      s[k++] = ch[i];
    }
    int num = 0;
    sort(s, s + k);
    for (int i = 0; i < k; i++) {
      num *= 10;
      num += (s[i] - '0');
      num %= 7;
    }
    num *= 10000;
    int q = num % 7;
    for (int i = 0; i < k; i++) printf("%c", s[i]);
    if (q == 0)
      printf("1869");
    else if (q == 1)
      printf("8196");
    else if (q == 2)
      printf("9861");
    else if (q == 3)
      printf("8691");
    else if (q == 4)
      printf("6198");
    else if (q == 5)
      printf("1689");
    else
      printf("1968");
    for (int i = 0; i < z; i++) printf("0");
    printf("\n");
  }
  return 0;
}
