#include <bits/stdc++.h>
using namespace std;
int countt[10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  vector<int> v = {1, 6, 8, 9};
  string aux;
  for (auto c : s) {
    int ok = 1;
    for (auto x : v) {
      if (x == c - '0' and countt[x] == 0) {
        countt[x] = 1;
        ok = 0;
        break;
      }
    }
    if (ok) aux += c;
  }
  sort(aux.begin(), aux.end());
  reverse(aux.begin(), aux.end());
  long long r = 0;
  for (auto c : aux) {
    r = (10 * r + (c - '0')) % 7;
  }
  r = (r * 10 * 10 * 10 * 10) % 7;
  do {
    long long acc = 0;
    for (auto x : v) {
      acc = (acc * 10 + x) % 7;
    }
    if ((r + acc) % 7 == 0) {
      long long ans = 0;
      if (aux.size() > 0 and aux[0] != '0') {
        cout << aux;
        for (auto p : aux) ans = (10 * ans + (p - '0')) % 7;
      }
      for (auto x : v) cout << x, ans = (10 * ans + x) % 7;
      if (aux.size() > 0 and aux[0] == '0') {
        cout << aux;
        for (auto p : aux) ans = (10 * ans + (p - '0')) % 7;
      }
      cout << '\n';
      return 0;
    }
  } while (next_permutation(v.begin(), v.end()));
  cout << 0 << '\n';
  return 0;
}
