#include <bits/stdc++.h>
using namespace std;
int r[4] = {1, 6, 8, 9};
int fastpow(int n) {
  int h = 1;
  int g = 10;
  while (n) {
    if (n % 2) h = h * g % 7;
    g = g * g % 7;
    n /= 2;
  }
  return h;
}
void deal(int le, int nl) {
  int dx = le * fastpow(nl + 4) % 7;
  do {
    int mlx = 0;
    for (int i : r) mlx = (mlx * 10 + i) % 7;
    mlx = mlx * fastpow(nl) % 7;
    if (dx == (7 - mlx) % 7) return;
  } while (next_permutation(r, r + 4));
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  bool one, six, eig, nin;
  one = six = eig = nin = false;
  int nulls = 0;
  int gebo = 0;
  string line;
  cin >> line;
  for (char& c : line) {
    int dx = c - '0';
    if (dx == 0)
      nulls += 1;
    else if (dx == 1 && !one)
      one = true;
    else if (dx == 6 && !six)
      six = true;
    else if (dx == 8 && !eig)
      eig = true;
    else if (dx == 9 && !nin)
      nin = true;
    else {
      cout << dx;
      gebo = (gebo * 10 + dx) % 7;
    }
  }
  deal(gebo, nulls);
  for (int i : r) cout << i;
  for (int i = 0; i < nulls; ++i) cout << "0";
  return 0;
}
