#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double eps = 1e-9;
const int maxn = (int)1e6 + 10;
char s[maxn];
int aa[4] = {1, 6, 8, 9};
int bb[4];
int cc[7];
void go(int x, int val) {
  if (x == 4) {
    if (cc[val % 7] == 0) cc[val % 7] = val;
  } else {
    for (int i = 0; (i) < (4); ++i) {
      if (bb[i] == 0) {
        bb[i] = 1;
        go(x + 1, val * 10 + aa[i]);
        bb[i] = 0;
      }
    }
  }
}
int nn[10];
int mn[10] = {0, 1, 0, 0, 0, 0, 1, 0, 1, 1};
char res[maxn];
int resc = 0;
int main() {
  go(0, 0);
  scanf("%s", s);
  int n = strlen(s);
  for (int i = 0; (i) < (n); ++i) nn[(int)(s[i] - '0')] += 1;
  int cur = 0;
  for (int i = 9; i > 0; --i)
    while (nn[i] > mn[i]) {
      res[resc++] = '0' + i;
      cur = (cur * 10 + i) % 7;
      nn[i] -= 1;
    }
  cur = (cur * 10000) % 7;
  cur = (7 - cur) % 7;
  res[resc] = 0;
  printf("%s", res);
  printf("%d", cc[cur]);
  for (int i = 0; (i) < (nn[0]); ++i) printf("0");
  printf("\n");
  return 0;
}
