#include <bits/stdc++.h>
int blah[] = {1, 3, 2, 6, 4, 5};
int invb[] = {1, 5, 4, 6, 2, 3};
using namespace std;
int DEBUG = 0;
int main(int argc, char **argv) {
  DEBUG = (argc >= 2) ? atoi(argv[1]) : 0;
  char num[1000005];
  cin >> num;
  int len = strlen(num);
  int d1 = 0, d6 = 0, d8 = 0, d9 = 0;
  int nm7 = 0;
  bool allzero = true;
  int nz = 0;
  for (int i = 0; i < len; i++) {
    if (num[i] == '0') nz++;
  }
  int dig = len - nz + 5;
  for (int i = 0; i < len; i++) {
    if (num[i] == '1' && !d1)
      d1 = 1;
    else if (num[i] == '6' && !d6)
      d6 = 1;
    else if (num[i] == '8' && !d8)
      d8 = 1;
    else if (num[i] == '9' && !d9)
      d9 = 1;
    else if (num[i] == '0')
      nz = nz + 1 - 1;
    else {
      cout << num[i];
      nm7 = (nm7 + ((num[i] - '0') * blah[dig % 6])) % 7;
      dig--;
    }
  }
  nm7 = (7 - nm7) % 7;
  switch (nm7) {
    case 0:
      cout << 9681;
      break;
    case 1:
      cout << 8961;
      break;
    case 2:
      cout << 6981;
      break;
    case 3:
      cout << 6891;
      break;
    case 4:
      cout << 8691;
      break;
    case 5:
      cout << 8916;
      break;
    case 6:
      cout << 8196;
      break;
  }
  for (int i = 0; i < nz; i++) {
    cout << 0;
  }
  cout << endl;
  return 0;
}
