#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
}
int a[7] = {1869, 1968, 1689, 6198, 1698, 1986, 1896}, b[4] = {1, 6, 8, 9};
int n, v[10];
char s[2000000];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= (n); ++i) {
    bool o = true;
    for (int j = (0); j <= (3); ++j)
      if (o && !v[b[j]] && s[i] == b[j] + 48) {
        v[b[j]] = 1;
        s[i--] = s[n--];
        o = false;
      }
    if (o && s[i] == '0') {
      ++v[0];
      s[i--] = s[n--];
    }
  }
  s[n + 1] = 0;
  int t(0);
  for (int i = 1; i <= (n); ++i) t = (t * 10 + s[i] - 48) % 7;
  t = t * 10000 % 7;
  printf("%s%d", s + 1, a[(7 - t) % 7]);
  for (int i = 1; i <= (v[0]); ++i) printf("0");
  printf("\n");
  return 0;
}
