#include <bits/stdc++.h>
using namespace std;
int main() {
  string S = "";
  cin >> S;
  int N = S.length();
  char retArr[N];
  bool isNeeded[10] = {false, true, false, false, false,
                       false, true, false, true,  true};
  bool hasDigit = false;
  int reti = 0;
  for (int i = 0; i < N; i++) {
    int digit = S[i] - '0';
    if (isNeeded[digit])
      isNeeded[digit] = false;
    else if (digit != 0) {
      hasDigit = true;
      retArr[reti++] = '0' + digit;
    } else
      retArr[reti++] = '0' + digit;
  }
  retArr[reti] = '\0';
  int rems[] = {1869, 1968, 1689, 6198, 1698, 1986, 1896};
  if (hasDigit) {
    N -= 4;
    int digInd = 0;
    for (; digInd < N && retArr[digInd] == '0'; digInd++)
      ;
    char temp = retArr[0];
    retArr[0] = retArr[digInd];
    retArr[digInd] = temp;
    int muls[] = {1, 3, 2, 6, 4, 5};
    int mulInd = 4;
    int sp = 0;
    for (int i = N - 1; i >= 0; i--) {
      int digit = retArr[i] - '0';
      sp += digit * muls[mulInd];
      mulInd = (mulInd + 1) % 6;
    }
    cout << retArr << rems[(7 - sp % 7) % 7];
  } else
    cout << rems[0] << retArr;
  cout << endl;
  return 0;
}
