#include <bits/stdc++.h>
using namespace std;
int p[7] = {8169, 8961, 9816, 6891, 8691, 8916, 8196}, ma[10];
char s[1000006];
int main() {
  scanf("%s", &s);
  int i = 0;
  while (s[i]) {
    ma[s[i] - '0']++;
    i++;
  }
  ma[1]--;
  ma[6]--;
  ma[8]--;
  ma[9]--;
  int k = 0;
  for (int j = 1; j <= 9; ++j) {
    for (int t = 0; t < ma[j]; ++t) {
      printf("%d", j);
      k = (k * 10 + j) % 7;
    }
  }
  k = (k * 10000) % 7;
  printf("%d", p[(7 - k) % 7]);
  for (int j = 0; j < ma[0]; ++j) printf("%d", 0);
}
