#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
long long Q = 1000000007;
long long binpow(long long val, long long deg, long long mod) {
  if (!deg) return 1 % mod;
  if (deg & 1) return binpow(val, deg - 1, mod) * val % mod;
  long long res = binpow(val, deg >> 1, mod);
  return (res * res) % mod;
}
int fin[7];
int fun[20];
int main() {
  int a[4] = {1, 6, 8, 9};
  while (next_permutation(a, a + 4)) {
    int t = 0;
    for (int i = 0; i < 4; i++) {
      t = t * 10 + a[i];
    }
    fin[t % 7] = t;
  }
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    fun[s[i] - '0']++;
  }
  fun[1]--;
  fun[6]--;
  fun[8]--;
  fun[9]--;
  int rem = 0;
  for (int i = 1; i <= 9; i++) {
    while (fun[i] > 0) {
      cout << i;
      rem = rem * 10 + i;
      rem %= 7;
      fun[i]--;
    }
  }
  int temp = 4;
  while (temp--) {
    rem = rem * 10;
    rem %= 7;
  }
  cout << fin[(7 - rem) % 7];
  while (fun[0]) {
    cout << "0";
    fun[0]--;
  }
  cout << "\n";
  return 0;
}
