#include <bits/stdc++.h>
const int N = 1000100;
char s[N], c[N];
int T[10];
inline int max(int a, int b) { return a > b ? a : b; }
int getd(char s[], int n) {
  int odd = 0, eve = 0;
  int xd = 1;
  for (int i = n - 1; i >= 0; i -= 3) {
    int now = 0;
    for (int j = max(0, i - 2); j <= i; j++) now = now * 10 + s[j] - '0';
    if (xd & 1)
      odd += now;
    else
      eve += now;
    xd ^= 1;
  }
  int ans = odd - eve;
  ans %= 7;
  if (ans < 0) ans += 7;
  return ans;
}
int XD(int p[]) {
  int a = 0;
  for (int i = 0; i < 4; i++) a = a * 10 + p[i];
  return a % 7;
}
void out(char c[], int n) {
  int top = 0;
  for (int i = 0; i < n; i++)
    if (c[i] != '0') {
      for (; i < n; i++) printf("%c", c[i]);
      break;
    } else
      top++;
  for (int i = 0; i < top; i++) printf("0");
}
int make(int top) {
  s[0] = '1';
  for (int i = 1; i <= top; i++) s[i] = '0';
  return getd(s, top + 1);
}
int main() {
  scanf("%s", s);
  int top = 0;
  int n = strlen(s);
  for (int i = 0; i < n; i++) {
    if (s[i] == '1' && !T[1])
      T[1] = true;
    else if (s[i] == '6' && !T[6])
      T[6] = true;
    else if (s[i] == '8' && !T[8])
      T[8] = true;
    else if (s[i] == '9' && !T[9])
      T[9] = true;
    else
      c[top++] = s[i];
  }
  int a = make(top);
  int r = getd(c, top);
  c[top] = 0;
  int p[4] = {1, 6, 8, 9};
  do {
    if ((XD(p) * a + r) % 7 == 0) {
      for (int i = 0; i < 4; i++) printf("%d", p[i]);
      break;
    }
  } while (std::next_permutation(p, p + 4));
  printf("%s\n", c);
}
