#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string w;
  cin >> w;
  vector<int> dig;
  vector<int> arr = {1, 6, 8, 9};
  for (auto c : w) dig.emplace_back(c - '0');
  sort(dig.begin(), dig.end());
  dig.erase(find(dig.begin(), dig.end(), 1));
  dig.erase(find(dig.begin(), dig.end(), 6));
  dig.erase(find(dig.begin(), dig.end(), 8));
  dig.erase(find(dig.begin(), dig.end(), 9));
  random_shuffle(dig.begin(), dig.end());
  do {
    int delta = 0;
    for (auto to : arr) delta = delta * 10 + to;
    delta %= 7;
    for (auto to : dig) {
      delta = delta * 10 + to;
      delta %= 7;
    }
    if (delta == 0) {
      for (auto to : arr) cout << to;
      for (auto to : dig) cout << to;
      return 0;
    }
  } while (next_permutation(arr.begin(), arr.end()));
  cout << 0 << '\n';
  return 0;
}
