#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, l, a[1000009], b[1000009], p[1000009], ans, cn, t, x, y, z,
    mx, mn, s, num, tmp;
char c[1000009], d[1000009], ch;
int main() {
  while (scanf("%s", c) != EOF) {
    memset(b, 0, sizeof(b));
    b[1] = b[6] = b[8] = b[9] = -1;
    l = strlen(c);
    for (i = 0; i < l; i++) {
      b[c[i] - '0']++;
    }
    num = 0;
    for (i = 1; i <= 9; i++) {
      for (j = 0; j < b[i]; j++) {
        printf("%d", i);
        num = num * 10 + i;
        num %= 7;
      }
    }
    p[0] = 1;
    p[1] = 6;
    p[2] = 8;
    p[3] = 9;
    do {
      tmp = 0;
      for (i = 0; i < 4; i++) {
        tmp = tmp * 10 + p[i];
      }
      if ((num * 10000 + tmp) % 7 == 0) {
        printf("%d", tmp);
        break;
      }
    } while (next_permutation(p, p + 4) != 0);
    for (i = 0; i < b[0]; i++) {
      printf("0");
    }
    printf("\n");
  }
  return 0;
}
