#include <bits/stdc++.h>
using namespace std;
char s[55] = "1689";
int a[10];
char b[1000005];
int c[1005] = {9681, 8196, 9861, 8691, 6891, 9816, 8961};
int main() {
  scanf("%s", &b);
  int i, j, in = 0;
  for (i = 0; b[i]; i++) a[b[i] - '0']++;
  a[1]--;
  a[6]--;
  a[8]--;
  a[9]--;
  int cur = 0;
  int non = 0;
  for (i = 1; i <= 9; i++) {
    for (j = 0; j < a[i]; j++) {
      non = 1;
      printf("%d", i);
      cur = (cur * 10 + i) % 7;
    }
  }
  if (non) {
    for (j = 0; j < a[0]; j++) {
      printf("0");
      cur = (cur * 10 + 0) % 7;
    }
    while (1) {
      int tmp = cur;
      for (i = 0; i < 4; i++) tmp = (tmp * 10 + s[i] - '0') % 7;
      if (tmp == 0) {
        printf("%s\n", s);
        break;
      }
      if (!next_permutation(s, s + 4)) break;
    }
  } else {
    printf("1869");
    for (j = 0; j < a[0]; j++) printf("0");
  }
  return 0;
}
