#include <bits/stdc++.h>
using namespace std;
int modulo(int x, int k, int m) {
  for (int i = 0; i < k; ++i) x = (x * 10) % m;
  return x;
}
int main() {
  string remainders[7];
  string s("1689");
  do {
    long n = strtol(s.c_str(), 0, 10);
    remainders[n % 7] = s;
  } while (next_permutation(s.begin(), s.begin() + 4));
  string data;
  cin >> data;
  bool already_have[10];
  fill(already_have, already_have + 10, true);
  already_have[1] = already_have[6] = already_have[8] = already_have[9] = false;
  string tmp("");
  int i = 0;
  int zeroes = 0;
  while (i < data.size()) {
    if (data[i] == '0') {
      ++zeroes;
    } else if (already_have[data[i] - '0']) {
      tmp.append(1, data[i]);
    } else {
      already_have[data[i] - '0'] = true;
    }
    ++i;
  }
  int prefix_rem = 0;
  if (tmp.size() != 0) {
    for (int i = 0; i < tmp.size(); ++i)
      prefix_rem = (prefix_rem * 10 + (tmp[i] - '0')) % 7;
  }
  prefix_rem = modulo(prefix_rem, 4 + zeroes, 7);
  int suffix_rem = modulo(1, zeroes, 7);
  int r = 0;
  while (r < 7) {
    if ((prefix_rem + modulo(r, zeroes, 7)) % 7 == 0) {
      break;
    }
    ++r;
  }
  cout << tmp << remainders[r];
  for (int i = 0; i < zeroes; ++i) cout << "0";
  cout << endl;
  return 0;
}
