#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool getmin(T *a, const T &b) {
  if (b < *a) {
    *a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool getmax(T *a, const T &b) {
  if (b > *a) {
    *a = b;
    return true;
  }
  return false;
}
template <class T>
inline void read(T *a) {
  char c;
  while (isspace(c = getchar())) {
  }
  bool flag = 0;
  if (c == '-')
    flag = 1, *a = 0;
  else
    *a = c - 48;
  while (isdigit(c = getchar())) *a = *a * 10 + c - 48;
  if (flag) *a = -*a;
}
const int mo = 1000000007;
template <class T>
T pow(T a, T b, int c = mo) {
  T res = 1;
  for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % c)
    if (b & i) res = 1LL * res * a % c;
  return res;
}
int num[10];
char c[1100000];
int main() {
  scanf("%s", c + 1);
  int n;
  n = strlen(c + 1);
  for (int i = (1); i <= (n); ++i) num[c[i] - '0']++;
  if (num[0] + 4 == n) {
    cout << 1869;
    for (int i = (1); i <= (num[0]); ++i) putchar('0');
    cout << endl;
    return 0;
  }
  --num[1];
  --num[6];
  --num[8];
  --num[9];
  int ans = 0;
  for (int i = (9); i >= (0); --i) {
    while (num[i]--) putchar('0' + i), ans = (ans * 10 + i) % 7;
  }
  ans = ans * 10000 % 7;
  int a[5];
  a[1] = 1;
  a[2] = 6;
  a[3] = 8;
  a[4] = 9;
  while (next_permutation(a + 1, a + 5)) {
    if (((1000 * a[1] + 100 * a[2] + 10 * a[3] + a[4]) % 7 + ans) % 7 == 0) {
      for (int i = (1); i <= (4); ++i) printf("%d", a[i]);
      cout << endl;
      return 0;
    }
  }
  return 0;
}
