#include <bits/stdc++.h>
using namespace std;
int solve() {
  vector<string> rem(7, "-1");
  string s = "1689";
  do {
    long long n = 0;
    for (long long int i = 0; i < 4; i++)
      n += (long long)pow(10, 3 - i) * (s[i] - '0');
    rem[n % 7] = s;
  } while (next_permutation(s.begin(), s.end()));
  cin >> s;
  string r;
  long long n = (long long int)s.size();
  vector<long long int> f(4, 0);
  for (long long int i = 0; i < n; i++) {
    if (s[i] == '1' && f[0] == 0) {
      f[0] = 1;
      continue;
    }
    if (s[i] == '6' && f[1] == 0) {
      f[1] = 1;
      continue;
    }
    if (s[i] == '8' && f[2] == 0) {
      f[2] = 1;
      continue;
    }
    if (s[i] == '9' && f[3] == 0) {
      f[3] = 1;
      continue;
    }
    r += s[i];
  }
  sort(r.begin(), r.end());
  reverse(r.begin(), r.end());
  string ans = "";
  long long reminder = 0;
  for (long long int i = 0; i < (long long int)r.size(); i++)
    reminder = ((r[i] - '0') + 10 * reminder) % 7;
  reminder = (reminder * (10000 % 7)) % 7;
  if ((long long int)r.size() > 0 && r[0] == '0')
    ans = rem[0] + r;
  else
    ans = r + rem[(7 - reminder) % 7];
  cout << ans << "\n";
  return 0;
}
int main() {
  auto start = chrono::high_resolution_clock::now();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test_cases = 1;
  while (test_cases--) solve();
  auto stop = chrono::high_resolution_clock::now();
  auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
}
