#include <bits/stdc++.h>
using namespace std;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int N = 5e5 + 7;
int primeset[100005];
vector<int> prime;
string mat[51];
int dp[52][52];
void solve() {
  string s, s2;
  cin >> s;
  string rem[7] = {"1869", "1896", "1986", "8691", "6891", "6918", "1968"};
  s2 = "";
  int zeros = 0;
  vector<int> v(10, 0);
  for (int i = 0; i < s.size(); ++i) {
    v[s[i] - '0']++;
  }
  v[1]--;
  v[8]--;
  v[6]--;
  v[9]--;
  string ans = "";
  int sz = s.size() - 4 - v[0];
  int remainder = 0;
  int j = 0;
  int pow10 = 1;
  for (int i = 1; i < 10; ++i) {
    while (v[i] > 0) {
      remainder += pow10 * i;
      remainder %= 7;
      pow10 *= 10;
      pow10 %= 7;
      v[i]--;
      ans += (i + '0');
    }
  }
  remainder *= 10000;
  remainder %= 7;
  reverse(ans.begin(), ans.end());
  ans += rem[remainder];
  while (v[0]--) {
    ans += '0';
  }
  cout << ans << endl;
}
int main() {
  int t;
  { solve(); }
}
unsigned long long mod_pow(unsigned long long num, unsigned long long pow,
                           unsigned long long mod) {
  unsigned long long test, n = num;
  for (test = 1; pow; pow >>= 1) {
    if (pow & 1) test = ((test % mod) * (n % mod)) % mod;
    n = ((n % mod) * (n % mod)) % mod;
  }
  return test;
}
long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int mpow(int base, int exp) {
  base %= 100000000000000007;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((long long)result * base) % 100000000000000007;
    base = ((long long)base * base) % 100000000000000007;
    exp >>= 1;
  }
  return result;
}
