#include <bits/stdc++.h>
using namespace std;
inline long long in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline string getStr() {
  char ch[1000000];
  scanf("%s", ch);
  return ch;
}
inline char getCh() {
  char ch;
  scanf(" %c", &ch);
  return ch;
}
template <class P, class Q>
inline P smin(P &a, Q b) {
  if (b < a) a = b;
  return a;
}
template <class P, class Q>
inline P smax(P &a, Q b) {
  if (a < b) a = b;
  return a;
}
const long long MOD = 1e9 + 7;
const long long MAX_N = 1e5 + 10;
const long long MAX_LG = 21;
const long long base = 29;
const long long MAX_DIF = 5005;
long long cnt[20];
long long cnt2[20];
long long num;
int32_t main() {
  string s = getStr();
  long long sz = (long long)s.size();
  for (long long i = 0; i < sz; i++) cnt[s[i] - '0']++;
  cnt[1]--, cnt[6]--, cnt[8]--, cnt[9]--;
  for (long long i = 0; i < s.size(); i++) {
    cnt2[s[i] - '0']++;
    if (cnt2[s[i] - '0'] > cnt[s[i] - '0'] || s[i] == '0') {
      continue;
    }
    cout << s[i];
    num = (10 * num + (s[i] - '0')) % 7;
  }
  for (long long i = 0; i < 4; i++) num = 10 * num % 7;
  if (num % 7 == 0) {
    cout << 1869;
  } else if (num % 7 == 1) {
    cout << 1896;
  } else if (num % 7 == 2) {
    cout << 1986;
  } else if (num % 7 == 3) {
    cout << 1698;
  } else if (num % 7 == 4) {
    cout << 6198;
  } else if (num % 7 == 5) {
    cout << 1689;
  } else {
    cout << 1968;
  }
  for (long long i = 0; i < cnt2[0]; i++) cout << 0;
}
