#include <bits/stdc++.h>
long long int power(long long int x, long long int n,
                    unsigned long long int m = ULLONG_MAX) {
  long long int res = 1;
  x %= m;
  while (n > 0) {
    if (n & 1 == 1) res = (res * x) % m;
    n /= 2;
    x = (x * x) % m;
  }
  return res;
}
using namespace std;
int i, j;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  long long int hash[10] = {0};
  for (i = 0; i <= s.length() - 1; ++i) ++hash[s[i] - '0'];
  string ans;
  for (i = 9; i >= 1; --i)
    while (hash[i] > 0) {
      if ((i == 1 || i == 6 || i == 8 || i == 9) && hash[i] == 1) break;
      ans += char(i + 48);
      --hash[i];
    }
  long long int car = 0;
  for (i = 0; i <= int(ans.length()) - 1; ++i)
    car = (ans[i] - '0' + car * 10) % 7;
  car = (car * power(10, 4, 1000000007)) % 7;
  string temp[7] = {"1869", "1968", "1689", "6198", "1698", "1986", "1896"};
  ans += temp[(7 - car) % 7];
  while (hash[0] > 0) {
    ans += char(48);
    --hash[0];
  }
  cout << ans << "\n";
}
