#include <bits/stdc++.h>
using namespace std;
long long n, ans, a[11], calc, b[111];
string s, t;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
int main() {
  cin >> s;
  for (long long i = 0; i < s.size(); i++) a[s[i] - 48]++;
  a[1]--, a[6]--, a[8]--, a[9]--;
  for (long long i = 1; i <= 9; i++)
    for (long long j = 1; j <= a[i]; j++) cout << i, calc = (calc * 10 + i) % 7;
  b[1] = 1, b[2] = 6, b[3] = 8, b[4] = 9;
  do {
    if ((calc * 10000 + b[1] * 1000 + b[2] * 100 + b[3] * 10 + b[4]) % 7 == 0) {
      cout << b[1] << b[2] << b[3] << b[4];
      break;
    }
  } while (next_permutation(b + 1, b + 5));
  for (long long j = 1; j <= a[0]; j++) cout << 0;
}
