#include <bits/stdc++.h>
using namespace std;
char s[1000009];
int main() {
  int mas[4] = {1, 6, 8, 9};
  vector<int> rest[7];
  while (next_permutation(mas, mas + 4)) {
    int s = 0;
    int d = 1;
    for (int j = 4 - 1; j >= 0; j--) {
      s += mas[j] * d;
      d *= 10;
    }
    if (rest[s % 7].size() == 0) {
      for (int j = 0; j < 4; j++) rest[s % 7].push_back(mas[j]);
    }
  }
  scanf("%s", s);
  int z = 0;
  bool f1 = false;
  bool f6 = false;
  bool f8 = false;
  bool f9 = false;
  vector<int> v;
  for (int i = 0; s[i]; i++) {
    if (s[i] == '0') {
      z++;
      continue;
    }
    if (s[i] == '1' && !f1) {
      f1 = true;
      continue;
    }
    if (s[i] == '6' && !f6) {
      f6 = true;
      continue;
    }
    if (s[i] == '8' && !f8) {
      f8 = true;
      continue;
    }
    if (s[i] == '9' && !f9) {
      f9 = true;
      continue;
    }
    int a = s[i] - '0';
    v.push_back(a);
    printf("%d", a);
  }
  int r = 0;
  if (v.size() > 0) {
    int d = 10000 % 7;
    for (int i = v.size() - 1; i >= 0; i--) {
      r += v[i] * d;
      d *= 10;
      r %= 7;
      d %= 7;
    }
  }
  for (int i = 0; i < 4; i++) printf("%d", rest[(7 - r) % 7][i]);
  for (int i = 0; i < z; i++) printf("0");
  printf("\n");
  return 0;
}
