#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long N = 3e5 + 7;
long long n;
string str;
long long arr[N];
bool check(string ans) {
  long long len = ans.length();
  long long num = 0;
  long long p = 1;
  for (long long i = len - 1; i >= 0; i--) {
    long long rem = ans[i] - '0';
    num = (num % 7 + p * rem) % 7;
    p = p * 10;
    p %= 7;
  }
  return num % 7;
}
void solve() {
  cin >> str;
  for (long long i = 0; i < str.size(); i++) arr[str[i] - '0']++;
  string str[7];
  string a = "1689";
  do {
    stringstream mafia(a);
    long long x;
    mafia >> x;
    str[x % 7] = a;
  } while (next_permutation(a.begin(), a.end()));
  arr[1]--;
  arr[6]--;
  arr[8]--;
  arr[9]--;
  string ans = "";
  for (long long i = 1; i < 10; i++) {
    while (arr[i] > 0) {
      char x = i + '0';
      ans += x;
      arr[i]--;
    }
  }
  long long len = ans.length();
  long long p = 1;
  long long num = 0;
  for (long long i = 0; i < 7; i++) {
    string temp = ans + str[i];
    if (check(temp) == 0) {
      while (arr[0] > 0) {
        char x = '0';
        temp += x;
        arr[0]--;
      }
      cout << temp;
      return;
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
}
