#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  vector<int> nz;
  int z = 0;
  for (int i = 0; i < (int)S.size(); i++)
    if (S[i] == '1') {
      S[i] = '#';
      break;
    }
  for (int i = 0; i < (int)S.size(); i++)
    if (S[i] == '8') {
      S[i] = '#';
      break;
    }
  for (int i = 0; i < (int)S.size(); i++)
    if (S[i] == '6') {
      S[i] = '#';
      break;
    }
  for (int i = 0; i < (int)S.size(); i++)
    if (S[i] == '9') {
      S[i] = '#';
      break;
    }
  for (int i = 0; i < (int)S.size(); i++) {
    if (S[i] == '#') continue;
    if (S[i] == '0')
      z++;
    else
      nz.push_back(S[i] - '0');
  }
  int f = 1;
  for (int i = 0; i < z; i++) {
    f *= 10;
    f %= 7;
  }
  int a[4] = {1, 8, 6, 9};
  int b[7] = {};
  sort(a, a + 4);
  do {
    int x = 0;
    for (int i = 0; i < 4; i++) {
      x *= 10;
      x += a[i];
    }
    b[(x * f) % 7] = x;
  } while (next_permutation(a, a + 4));
  sort(nz.begin(), nz.end());
  int w = 1;
  for (int i = 0; i < z + 4; i++) {
    w *= 10;
    w %= 7;
  }
  int tot = 0;
  for (int i = 0; i < (int)nz.size(); i++) {
    tot += w * nz[i];
    tot %= 7;
    w *= 10;
    w %= 7;
  }
  int req = (7 - tot) % 7;
  reverse(nz.begin(), nz.end());
  for (int i = 0; i < (int)nz.size(); i++) cout << nz[i];
  cout << b[req];
  for (int i = 0; i < z; i++) cout << "0";
  cout << "\n";
}
