#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll md = 1000000007;
ll exp(ll a, ll b) {
  ll r = 1ll;
  while (b > 0) {
    if (b & 1) {
      r = r * (a % md);
      r = (r + md) % md;
    }
    b >>= 1;
    a = (a % md) * (a % md);
    a = (a + md) % md;
  }
  return (r + md) % md;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
T Min(T a, T b) {
  if (a < b) return a;
  return b;
}
template <class T>
T Max(T a, T b) {
  if (a > b) return a;
  return b;
}
long long cnt[10];
string curr;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  for (auto& c : s) ++cnt[c - '0'];
  if (cnt[0] == (long long)(s).size() - 4) {
    cout << "1869";
    for (ll i = 1; i <= cnt[0]; ++i) cout << "0";
    return 0;
  }
  vector<ll> v = {1, 8, 6, 9};
  for (auto& x : v) --cnt[x];
  for (ll i = 9; i >= 0; --i)
    for (ll j = 1; j <= cnt[i]; ++j) curr += (i + '0');
  long long rem = 0;
  for (auto& c : curr) rem = (rem * 10 + c - '0') % 7;
  do {
    long long crem = rem;
    for (ll i = 0; i <= 3; ++i) crem = (crem * 10 + v[i]) % 7;
    if (crem == 0) {
      cout << curr;
      for (ll i = 0; i <= 3; ++i) cout << v[i];
      cout << '\n';
      return 0;
    }
  } while (next_permutation((v).begin(), (v).end()));
  cout << "0";
  return 0;
}
