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