#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int dX[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dY[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int resto[7];
char s[1000100], t[1000100];
int main(void) {
  int dig[] = {1, 6, 8, 9};
  memset(((resto)), (-1), sizeof(((resto))));
  for (int((a)) = (0); ((a)) < ((4)); ((a))++)
    for (int((b)) = (0); ((b)) < ((4)); ((b))++)
      if (b != a)
        for (int((c)) = (0); ((c)) < ((4)); ((c))++)
          if (c != a && c != b)
            for (int((d)) = (0); ((d)) < ((4)); ((d))++)
              if (d != c && d != b && d != a) {
                int x = dig[a] * 1000 + dig[b] * 100 + dig[c] * 10 + dig[d];
                resto[x % 7] = x;
              }
  int p[4];
  scanf("%s", s);
  for (int((R)) = (0); ((R)) < ((7)); ((R))++) {
    int r = R;
    int l = 0;
    memset(((p)), (-1), sizeof(((p))));
    for (int i = 0; s[i]; i++) {
      int x = (int)(s[i] - '0');
      int ok = 1;
      for (int((j)) = (0); ((j)) < ((4)); ((j))++)
        if (p[j] < 0 && dig[j] == x) {
          p[j] = i;
          ok = 0;
          break;
        }
      if (ok) {
        r = ((r * 10) + x) % 7;
        t[l++] = s[i];
      }
    }
    t[l] = 0;
    if (r == 0) {
      printf("%d%s\n", resto[R], t);
      break;
    }
  }
  return 0;
}
