#include <bits/stdc++.h>
using namespace std;
int main() {
  string pull[] = {"1869", "6198", "1896", "9186", "9168", "6189", "8691"};
  string S;
  cin >> S;
  long long arr[10] = {0}, rem = 0;
  for (long long i = 0; i < S.length(); i++) arr[S[i] - '0']++;
  arr[1]--;
  arr[6]--;
  arr[8]--;
  arr[9]--;
  for (long long i = 1; i < 10; i++) {
    while (arr[i]) {
      cout << i;
      rem = rem * 10 + i;
      rem = rem % 7;
      arr[i]--;
    }
  }
  cout << pull[rem];
  while (arr[0]) {
    cout << 0;
    arr[0]--;
  }
}
