#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1073741824")
using namespace std;
const int C = 7, MAX = 1e6 + 100;
int ar[C], d[4] = {1, 6, 8, 9};
char s[MAX];
bool used[4];
int main() {
#pragma warning(disable : 4996)
  scanf("%s", s);
  int len = strlen(s);
  do {
    int a = 0, p = 1;
    for (int i = 3; i >= 0; i--, p *= 10) a += d[i] * p;
    ar[a % 7] = a;
  } while (next_permutation(d, d + 4));
  for (int i = 0; i < len; i++) {
    for (int j = 0; j < 4; j++) {
      if (s[i] - '0' == d[j] && !used[j]) {
        used[j] = 1;
        s[i] = '0';
      }
    }
  }
  sort(s, s + len, greater<int>());
  if (s[0] == '0') {
    printf("%d", ar[0]);
    for (int i = 0; i < len - 4; i++) printf("0");
  } else {
    int rest = 0;
    for (int i = 0; i < len; i++) {
      rest = (rest * 10 + s[i] - '0') % 7;
    }
    for (int i = len - 4; i < len; i++) s[i] = 0;
    printf("%s%d", s, ar[(7 - rest) % 7]);
  }
  return 0;
}
