#include <bits/stdc++.h>
using namespace std;
int bigMod(int a, int b, int c) {
  if (b == 0) return 1;
  if (b == 1) return a % c;
  int mid = bigMod(a, b / 2, c);
  int ans = mid * mid * bigMod(a, b % 2, c);
  ans %= c;
  return ans;
}
int main() {
  int A[10] = {0};
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    A[s[i] - '0']++;
  }
  int D[4] = {1, 6, 8, 9};
  map<int, int> z;
  do {
    int x = D[3] + 10 * D[2] + 100 * D[1] + 1000 * D[0];
    z[x % 7] = x;
  } while (next_permutation(D, D + 4));
  for (int i = 0; i < 4; i++) A[D[i]]--;
  bool allZ = true;
  for (int d = 9; d >= 1; d--)
    if (A[d]) allZ = false;
  if (allZ) {
    D[0] = 1;
    D[1] = 6;
    D[2] = 8;
    D[3] = 9;
    do {
      int x = D[3] + 10 * D[2] + 100 * D[1] + 1000 * D[0];
      int mod = 0, pos = s.length() - 1;
      for (int i = 3; i >= 0; i--) {
        mod += (D[i] % 7) * bigMod(10, pos, 7);
        mod %= 7;
        pos--;
      }
      if (mod == 0) {
        cout << x;
        for (int i = 0; i < A[0]; i++) cout << 0;
        cout << endl;
        return 0;
      }
    } while (next_permutation(D, D + 4));
  }
  int mod = 0, pos = s.length() - 1, dig = 9;
  for (int d = 9; d >= 1; d--) {
    for (int a = 1; a <= A[d]; a++) {
      mod += (d % 7) * bigMod(10, pos, 7);
      mod %= 7;
      pos--;
    }
  }
  for (int i = 0; i < 7; i++) {
    if ((mod + i) % 7 == 0) {
      for (int d = 9; d >= 0; d--) {
        while (A[d]--) cout << d;
      }
      cout << z[i] << endl;
      break;
    }
  }
  return 0;
}
