#include <bits/stdc++.h>
using namespace std;
string remDigits;
int main() {
  string rem[7] = {"1869", "1968", "1689", "6198", "1698", "1986", "1896"};
  int flag[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  char c;
  while (((c = getchar()) != '\n') && (c != EOF)) {
    if (c != '1' && c != '6' && c != '8' && c != '9')
      remDigits.push_back(c);
    else {
      if (flag[c - '0']) {
        remDigits.push_back(c);
      }
      flag[c - '0'] = 1;
    }
  }
  if (remDigits.empty()) {
    cout << 1869 << endl;
  } else {
    if (*(remDigits.begin()) == '0') {
      for (string::iterator it = remDigits.begin() + 1; it != remDigits.end();
           ++it) {
        if (*it != '0') {
          char temp = *it;
          *it = '0';
          *(remDigits.begin()) = temp;
          break;
        }
      }
    }
    if (*(remDigits.begin()) == '0') {
      string number = rem[0], padding(remDigits.length(), '0');
      number += padding;
      cout << number << endl;
    } else {
      int mod;
      mod = *(remDigits.begin()) - '0';
      for (string::iterator it = remDigits.begin() + 1; it != remDigits.end();
           ++it) {
        mod = (3 * mod + (*it - '0')) % 7;
      }
      mod = (mod * 4) % 7;
      remDigits += rem[(7 - mod) % 7];
      cout << remDigits << endl;
    }
  }
  return 0;
}
