#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void see(T&... args) {
  ((cin >> args), ...);
}
template <typename... T>
void put(T&&... args) {
  ((cout << args << " "), ...);
  cout << '\n';
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << ", ";
  err(++it, args...);
}
const long long inf = INT_MAX;
const long double ep = 0.0000001;
const long double pi = acos(-1.0);
const long long md = 1000000007;
vector<string> add = {"1869", "1968", "6918", "6198", "1698", "1986", "1896"};
void solve() {
  string s;
  see(s);
  long long a = 0, b = 0, c = 0, d = 0;
  string s1 = "";
  for (long long i = 0; i < s.size(); ++i) {
    if (s[i] == '1' && !a) {
      a = 1;
    } else if (s[i] == '6' && !b) {
      b = 1;
    } else if (s[i] == '8' && !c) {
      c = 1;
    } else if (s[i] == '9' && !d) {
      d = 1;
    } else
      s1 += s[i];
  }
  long long s3;
  for (long long j = 0; j < 7; ++j) {
    s3 = j;
    for (long long i = 0; i < s1.size(); ++i) {
      s3 = (s3 * 10 + (s1[i] - '0')) % 7;
    }
    if (s3 == 0) {
      s3 = j;
      break;
    }
  }
  s1 = add[s3] + s1;
  cout << s1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  solve();
}
