#include <bits/stdc++.h>
using namespace std;
char ar[] = "1689", s[1000010];
int val[10], ct[10];
int main() {
  do {
    val[atoi(ar) % 7] = atoi(ar);
  } while (next_permutation(ar, ar + 4));
  scanf("%s", s);
  int len = strlen(s);
  for (int i = 0; i < len; ++i) ct[s[i] - '0']++;
  for (int i = 0; i < 4; ++i) ct[ar[i] - '0']--;
  int rem = 0, div = 0;
  for (int i = 1; i < 10; ++i) {
    while (ct[i]--) {
      printf("%d", i);
      div = rem * 10 + i;
      rem = div % 7;
    }
  }
  rem *= 10000;
  for (int i = 0; i < 7; ++i)
    if (!((val[i] + rem) % 7)) {
      printf("%d", val[i]);
      while (ct[0]--) printf("0");
      printf("\n");
      return 0;
    }
  return 0;
}
