#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int dCounter[10], r3 = 0;
  string perm[7] = {"1869", "6198", "1896", "1689", "1986", "1968", "1698"};
  memset(dCounter, 0, sizeof dCounter);
  string n;
  vector<string> fs;
  cin >> n;
  for (int i = 0; i < n.length(); i++) dCounter[n[i] - '0']++;
  dCounter[1]--;
  dCounter[6]--;
  dCounter[8]--;
  dCounter[9]--;
  for (int i = 1; i < 10; i++) {
    while (dCounter[i]) {
      r3 = (r3 * 3 + i) % 7;
      cout << i;
      dCounter[i]--;
    }
  }
  cout << perm[r3];
  while (dCounter[0]--) cout << "0";
  cout << endl;
  return 0;
}
