#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
char str[1111111];
int k[] = {1869, 1968, 1689, 6198, 1698, 1986, 1896};
int cnt[10];
int q[] = {5, 4, 6, 2, 3, 1};
int main() {
  int tmp = 0;
  cin >> str;
  int n = strlen(str);
  for (int i = (0); i < (n); ++i) cnt[str[i] - '0']++;
  n -= cnt[0];
  cnt[1]--;
  cnt[6]--;
  cnt[8]--;
  cnt[9]--;
  int x = 1;
  for (int i = (0); i < (n - 4); ++i) {
    while (cnt[x] == 0) x++;
    cnt[x]--;
    printf("%d", x);
    tmp += q[5 - (n - i - 1) % 6] * x;
  }
  printf("%d", k[(7 - tmp % 7) % 7]);
  for (int i = (0); i < (cnt[0]); ++i) printf("0");
  printf("\n");
  return 0;
}
