#include <bits/stdc++.h>
using namespace std;
long long countingArray[10];
void print(vector<long long>& a) {
  for (long long i = 0; i < a.size(); i++) {
    cout << a[i];
  }
  cout << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string digits;
  cin >> digits;
  for (long long i = 0; i < digits.size(); i++) {
    countingArray[digits[i] - '0']++;
  }
  countingArray[1]--;
  countingArray[6]--;
  countingArray[8]--;
  countingArray[9]--;
  long long finalRem = 0;
  vector<long long> finalAnswer;
  for (long long i = 1; i <= 9; i++) {
    for (long long j = 0; j < countingArray[i]; j++) {
      finalRem = finalRem * 10 + i;
      finalRem = finalRem % 7;
      finalAnswer.push_back(i);
    }
  }
  if (finalRem == 0) {
    finalAnswer.push_back(1869);
  }
  if (finalRem == 1) {
    finalAnswer.push_back(6891);
  }
  if (finalRem == 2) {
    finalAnswer.push_back(1896);
  }
  if (finalRem == 3) {
    finalAnswer.push_back(1689);
  }
  if (finalRem == 4) {
    finalAnswer.push_back(1986);
  }
  if (finalRem == 5) {
    finalAnswer.push_back(1968);
  }
  if (finalRem == 6) {
    finalAnswer.push_back(1698);
  }
  for (long long i = 0; i < countingArray[0]; i++) finalAnswer.push_back(0);
  print(finalAnswer);
  return 0;
}
