#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;
int a[MAX_N];
int m[10];
void Permutation() {
  int a[] = {1, 6, 8, 9};
  do {
    const int x = 1000 * a[3] + 100 * a[2] + 10 * a[1] + 1 * a[0];
    m[x % 7] = x;
  } while (next_permutation(a, a + 4));
}
int f(int k) { return m[k]; }
int main() {
  Permutation();
  string s;
  cin >> s;
  const int n = s.size();
  for (int i = 0; i < (n); ++i) ++a[s[i] - '0'];
  a[1]--;
  a[6]--;
  a[8]--;
  a[9]--;
  int k = 0;
  for (int i = 0; i < (10); ++i) {
    if (i == 0) continue;
    for (int j = 0; j < (a[i]); ++j) {
      k = (10 * k + i) % 7;
      putchar('0' + i);
    }
  }
  k *= 10000;
  printf("%d", f((777777 - k) % 7));
  for (int j = 0; j < (a[0]); ++j) putchar('0');
  putchar('\n');
  return 0;
}
