#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename T>
constexpr int infValue =
    std::is_same<T, int>::value ? 2000100007 : 8600000000000000007ll;
template <typename T>
constexpr int maxValue =
    std::is_same<T, int>::value ? 1000000007 : 1000000000000000001ll;
const int INF = infValue<int>;
const long long MOD = 998244353ll;
const double EPS = 1e-6;
const int MAX = maxValue<int>;
using pr = pair<int, int>;
int n;
char s[1001050];
int get(int i) {
  if (i < 0) return 0;
  return s[i] - '0';
}
bool test() {
  int x = 0, sum = 0, d = 1;
  for (int i = n - 1; i >= 0; i -= 3) {
    x = get(i) + get(i - 1) * 10 + get(i - 2) * 100;
    sum += d * x;
    d *= -1;
  }
  return (sum % 7);
}
int cnt[10];
int dd = 1689;
bool u[10];
bool can(void) {
  int x = dd;
  int i = n - 1;
  bool fail = false;
  u[1] = u[6] = u[8] = u[9] = true;
  while (x) {
    int p = x % 10;
    if (u[p])
      s[i--] = p + '0';
    else
      fail = true;
    u[p] = false;
    x /= 10;
  }
  ++dd;
  return fail;
}
void perm(void) {
  while (dd < 10000 && can())
    ;
}
int main(void) {
  scanf("%s", s);
  while (s[n]) ++cnt[s[n++] - '0'];
  int j = 0;
  for (register int i = 9; i > 0; --i) {
    int d = i == 1 || i == 6 || i == 8 || i == 9;
    while (cnt[i] - d) {
      s[j++] = '0' + i;
      --cnt[i];
    }
  }
  n -= cnt[0];
  int z = cnt[0];
  do {
    perm();
  } while (test());
  while (z--) s[n++] = '0';
  puts(s);
  return 0;
}
