#include <bits/stdc++.h>
using namespace std;
int a[1001000] = {0}, b = 0, cnt = 0, d, e[12] = {0};
char c[1001000] = {0};
int main() {
  int i, j, k = 0, T;
  scanf("%s", &c);
  d = strlen(c);
  for (i = 0; i < d; i++) {
    if (c[i] == 48) {
      cnt++;
      a[i]++;
    } else if (c[i] == '1' && e[1] == 0) {
      a[i]++;
      e[1] = 1;
    } else if (c[i] == '6' && e[6] == 0) {
      a[i]++;
      e[6] = 1;
    } else if (c[i] == '8' && e[8] == 0) {
      a[i]++;
      e[8] = 1;
    } else if (c[i] == '9' && e[9] == 0) {
      a[i]++;
      e[9] = 1;
    } else {
      b = b * 10 + c[i] - 48;
      b = b % 7;
      printf("%c", c[i]);
    }
  }
  b = b * 10000;
  b = b % 7;
  b = (7 - b) % 7;
  if (b == 0) printf("1869");
  if (b == 1) printf("1968");
  if (b == 2) printf("1689");
  if (b == 3) printf("6198");
  if (b == 4) printf("1698");
  if (b == 5) printf("1986");
  if (b == 6) printf("1896");
  for (i = 1; i <= cnt; i++) {
    printf("0");
  }
  return 0;
}
