#include <bits/stdc++.h>
using namespace std;
int main() {
  string num;
  cin >> num;
  int pos[] = {1869, 6198, 1896, 9186, 9168, 6189, 8691};
  int hashtb[10] = {
      0,
  };
  int dig;
  for (int i = 0; i < num.length(); i++) {
    dig = num[i] - '0';
    hashtb[dig]++;
  }
  hashtb[1]--;
  hashtb[6]--;
  hashtb[8]--;
  hashtb[9]--;
  int rem = 0;
  for (int i = 1; i < 10; i++) {
    while (hashtb[i] > 0) {
      printf("%d", i);
      hashtb[i]--;
      rem = rem * 10 + i;
      rem %= 7;
    }
  }
  printf("%d", pos[rem]);
  while (hashtb[0] > 0) {
    printf("%d", 0);
    hashtb[0]--;
  }
  printf("\n");
}
