#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void pp(T... args) {
  ((cout << args << " "), ...);
  cout << "\n";
}
template <typename... T>
void po(T... args) {
  ((cout << args << " "), ...);
  cout << "";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int test = 1;
  for (int tt = 1; tt <= test; tt++) {
    string s, str = "";
    cin >> s;
    long long int n = s.size();
    long long int ch[10] = {0};
    long long int k = 0, p = 1, z = 0;
    for (long long int i = 0; i < n; i++) {
      if (s[i] == '1') {
        if (ch[1] == 0) {
          ch[1] = 1;
        } else {
          str += '1';
        }
      } else if (s[i] == '6') {
        if (ch[6] == 0) {
          ch[6] = 6;
        } else {
          str += '6';
        }
      } else if (s[i] == '8') {
        if (ch[8] == 0) {
          ch[8] = 8;
        } else {
          str += '8';
        }
      } else if (s[i] == '9') {
        if (ch[9] == 0) {
          ch[9] = 9;
        } else {
          str += '9';
        }
      } else {
        if (s[i] != '0')
          str += s[i];
        else
          z++;
      }
    }
    cout << str;
    k = 0;
    p = 10000;
    long long int num = str.size();
    for (long long int i = num - 1; i >= 0; i--) {
      k += (str[i] - '0') * p;
      k %= 7;
      p *= 10;
      p %= 7;
    }
    k = 7 - k;
    if (k == 0) cout << "1869";
    if (k == 1) cout << "1968";
    if (k == 2) cout << "1689";
    if (k == 3) cout << "6891";
    if (k == 4) cout << "1698";
    if (k == 5) cout << "1986";
    if (k == 6) cout << "1896";
    if (k == 7) cout << "1869";
    for (long long int i = 0; i < z; i++) {
      cout << "0";
    }
  }
  return 0;
}
