#include <bits/stdc++.h>
using namespace std;
char str[1010001];
int num[1010001];
char addstr[7][11] = {"1869", "1968", "1689", "6198", "1698", "1986", "1896"};
int main() {
  int n, m, i, a, b, c;
  while (~scanf("%s", str)) {
    int len = strlen(str);
    for (i = 0; i < len; i++) {
      num[i] = str[i] - '0';
    }
    int ll[11];
    memset(ll, 0, sizeof(ll));
    for (i = 0; i < len; i++) {
      if (num[i] == 1 && ll[1] == 0) {
        num[i] = 0;
        ll[1]++;
      }
      if (num[i] == 6 && ll[6] == 0) {
        num[i] = 0;
        ll[6]++;
      }
      if (num[i] == 8 && ll[8] == 0) {
        num[i] = 0;
        ll[8]++;
      }
      if (num[i] == 9 && ll[9] == 0) {
        num[i] = 0;
        ll[9]++;
      }
    }
    sort(num, num + len);
    int ss = 0;
    for (i = len - 1; i >= 0; i--) {
      ss = ss * 10 + num[i];
      ss = ss % 7;
    }
    int lls = 0;
    int leap = 0;
    for (i = len - 1; i >= 4; i--) {
      if (num[i] == 0 && leap == 0) {
        lls++;
      } else {
        cout << num[i];
        leap = 1;
      }
    }
    cout << addstr[(7 - ss) % 7];
    for (i = 0; i < lls; i++) {
      cout << "0";
    }
    cout << endl;
  }
  return 0;
}
