#include <bits/stdc++.h>
using namespace std;
template <class T>
typename T::value_type arr_sum(const T& v, int n) {
  typename T::value_type sum = 0;
  for (int i = 0; i < n; ++i) sum += v[i];
  return sum;
}
struct Sync_stdio {
  Sync_stdio() { ios_base::sync_with_stdio(false); }
} _sync_stdio;
int main() {
  vector<string> v = {"1869", "1968", "1689", "6198", "1698", "1986", "1896"};
  string s;
  cin >> s;
  int t = strchr(s.c_str(), '1') - s.c_str();
  s.erase(s.begin() + t);
  t = strchr(s.c_str(), '6') - s.c_str();
  s.erase(s.begin() + t);
  t = strchr(s.c_str(), '8') - s.c_str();
  s.erase(s.begin() + t);
  t = strchr(s.c_str(), '9') - s.c_str();
  s.erase(s.begin() + t);
  int i = 0;
  while (i < s.size() && s[i] == '0') {
    ++i;
  }
  if (i == s.size()) {
    cout << v[0];
    for (int i = 0; i < s.size(); ++i) {
      cout << '0';
    }
    return 0;
  }
  s.erase(s.begin(), s.begin() + i);
  for (int j = 0; j < i; ++j) {
    s += '0';
  }
  s += v[0];
  int tmp = 0;
  for (int i = 0; i < s.size(); ++i) {
    tmp *= 10;
    tmp += s[i] - '0';
    tmp %= 7;
  }
  for (int i = 0; i < 4; ++i) {
    s.pop_back();
  }
  s += v[(7 - tmp) % 7];
  cout << s;
  return 0;
}
