#include <bits/stdc++.h>
using namespace std;
int dX[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dY[] = {1, -1, 0, 0, 1, -1, -1, 1};
int main() {
  string s;
  cin >> s;
  s.erase(s.find('1'), 1);
  s.erase(s.find('8'), 1);
  s.erase(s.find('9'), 1);
  s.erase(s.find('6'), 1);
  bool d = 0;
  if ((s.size()) && s[0] == '0') {
    for (int i = 1; i < (s.size()); ++i)
      if (s[i] != '0') swap(s[i], s[0]), d = 1;
    if (!d) {
      cout << "1869" << s;
      return 0;
    }
  }
  int rem = 0;
  for (int i = 0; i < (s.size()); ++i) rem = rem * 10 + s[i] - '0', rem %= 7;
  string n = "1689";
  do {
    int r = rem;
    for (int i = 0; i < (n.size()); ++i) r = r * 10 + n[i] - '0', r %= 7;
    if (!r) break;
  } while (next_permutation(n.begin(), n.end()));
  cout << s << n;
  return 0;
}
