#include <bits/stdc++.h>
using namespace std;
int pois[10];
int omapow(int a, int b) {
  int x = 1;
  for (int i = 1; i <= b; i++) x *= a;
  return x;
}
int main() {
  string a;
  int nollat = 0;
  cin >> a;
  for (int i = 0; i < a.size(); ++i) {
    a[i] -= '0';
    if (a[i] == 1 || a[i] == 6 || a[i] == 8 || a[i] == 9) {
      if (!pois[a[i]]) {
        pois[a[i]] = 1;
        a.erase(a.begin() + i);
        --i;
      }
    }
  }
  sort(a.begin(), a.end());
  if (a.size() && a.back() == 0) {
    nollat = a.size();
    a.clear();
  }
  int cute = 10000;
  cute %= 7;
  int qwe = 0;
  for (int i = 0; i < a.size(); ++i) {
    qwe += (a[i] * cute) % 7;
    cute *= 10;
    cute %= 7;
    qwe %= 7;
  }
  for (auto& x : a) {
    x += 48;
  }
  for (int i = a.size() - 1; i >= 0; --i) {
    cout << a[i];
  }
  vector<int> lol = {1, 6, 8, 9};
  do {
    int q = 0;
    for (int i = 3; i >= 0; --i) {
      q += omapow(10, 3 - i) * lol[i];
    }
    if ((qwe + q) % 7 == 0) {
      for (auto x : lol) cout << x;
      goto jee;
    }
  } while (next_permutation(lol.begin(), lol.end()));
jee:;
  for (int i = 0; i < nollat; ++i) {
    cout << 0;
  }
  cout << '\n';
}
