#include <bits/stdc++.h>
using namespace std;
int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int c[4] = {1, 6, 8, 9};
char s[1010001];
inline int calc() {
  register int ans = 0;
  for (int i = 0; s[i]; ++i) {
    ans *= 10;
    ans += s[i] - '0';
    if (ans >= 7) ans %= 7;
  }
  return ans;
}
int main() {
  scanf("%s", s);
  for (int i = 0; s[i]; ++i) {
    for (int k = 0; k < 4; ++k)
      for (int j = 0; j < 4; ++j)
        if (s[i] == c[j] + '0') swap(s[i], s[j]);
  }
  do {
    if (calc() == 0) break;
  } while (next_permutation(s, s + 4));
  printf("%s\n", s);
  return 0;
}
