#include <bits/stdc++.h>
int return_reminder(char *a, int n) {
  if (n == 0) return 0;
  int num = 0;
  for (int i = 0; a[i] != '\0' && a[i] != '\n'; i++) {
    num = num * 10 + (a[i] - '0');
    num = num % 7;
  }
  return (num * 10000) % 7;
}
int *rem_add;
char *temp_s;
char *main_s;
int size_temp, size_main;
int ta[10];
int deb[10];
int debug = 1;
int main() {
  rem_add = (int *)calloc(7, sizeof(int));
  rem_add[0] = 1869;
  rem_add[1] = 1896;
  rem_add[2] = 1986;
  rem_add[3] = 1698;
  rem_add[4] = 6198;
  rem_add[5] = 1689;
  rem_add[6] = 1968;
  temp_s = (char *)calloc(1000010, sizeof(char));
  main_s = (char *)calloc(1000010, sizeof(char));
  scanf("%s", temp_s);
  size_temp = strlen(temp_s);
  int count = 0;
  for (int i = 0; temp_s[i] != '\n' && temp_s[i] != '\0'; i++) {
    if (temp_s[i] == '1' || temp_s[i] == '8' || temp_s[i] == '6' ||
        temp_s[i] == '9') {
      if (ta[temp_s[i] - '0'] == 0) {
        ta[temp_s[i] - '0'] = 1;
        continue;
      } else {
        main_s[count] = temp_s[i];
      }
    } else {
      main_s[count] = temp_s[i];
    }
    count++;
  }
  main_s[count] = '\0';
  size_main = count;
  if (count == 0) {
    printf("%d\n", rem_add[0]);
    return 0;
  } else if (main_s[0] == '0') {
    if (count == 1) {
      printf("%d0\n", rem_add[0]);
      return 0;
    } else {
      int pos = -1;
      for (int i = 0; i < size_main; i++) {
        if (main_s[i] != '0') {
          pos = 1;
          char temp = main_s[i];
          main_s[i] = main_s[0];
          main_s[0] = temp;
          break;
        }
      }
      if (pos == -1) {
        printf("%d", rem_add[0]);
        for (int i = 0; main_s[i] != '\0' && main_s[i] != '\n'; i++) {
          printf("%c", main_s[i]);
        }
        return 0;
      }
    }
  }
  printf("%s", main_s);
  int ttt = return_reminder(main_s, count);
  assert(ttt >= 0);
  printf("%d", rem_add[ttt]);
}
