#include <bits/stdc++.h>
using namespace std;
int mp[10];
int main() {
  string s;
  cin >> s;
  int len = s.size();
  for (int i = 0; i < len; i++) {
    mp[s[i] - '0']++;
  }
  mp[1]--;
  mp[6]--;
  mp[8]--;
  mp[9]--;
  int mod = 0;
  for (int i = 1; i <= 9; i++) {
    while (mp[i] != 0) {
      mod = (mod * 10 + i) % 7;
      mp[i]--;
      cout << i;
    }
  }
  int t = 4;
  while (t--) {
    mod = (mod * 10 + 0) % 7;
  }
  if (mod == 0) {
    cout << "1869";
  }
  if (mod == 1) {
    cout << "8196";
  }
  if (mod == 2) {
    cout << "8916";
  }
  if (mod == 3) {
    cout << "8691";
  }
  if (mod == 4) {
    cout << "6891";
  }
  if (mod == 5) {
    cout << "6981";
  }
  if (mod == 6) {
    cout << "1968";
  }
  while (mp[0] != 0) {
    cout << 0;
    mp[0]--;
  }
  cout << endl;
}
