#include <bits/stdc++.h>
using namespace std;
bool check(string s) {
  int md = 0;
  for (auto c : s) md = (md * 10 + c - '0') % 7;
  return (md == 0);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  vector<int> cunt(10);
  for (int i = 0; i < s.size(); i++) {
    cunt[s[i] - '0']++;
  }
  string zero = string(cunt[0], '0'), fr = "";
  int mod = 0, sum = 0;
  for (auto a : {1, 8, 9, 6}) cunt[a]--;
  string ss = "1689";
  for (int i = 1; i < 10; i++) {
    if (cunt[i]) fr += string(cunt[i], i + '0');
    while (cunt[i]) cunt[i]--, sum = (sum * 10 + i) % 7;
  }
  while (next_permutation(ss.begin(), ss.begin() + 4)) {
    if (check(fr + ss)) {
      cout << fr + ss;
      break;
    }
  }
  cout << zero;
}
