#include <bits/stdc++.h>
using namespace std;
int vis[10010000];
int main() {
  char a[1001000];
  scanf("%s", a);
  memset(vis, 0, sizeof(vis));
  int mod = 0;
  int l = strlen(a);
  int p = 0;
  int w = 0, e = 0, r = 0, t = 0;
  for (int i = 0; i < l; i++) {
    int we = (a[i] - '0');
    if (we == 0) {
      p++;
      vis[i] = 1;
      continue;
    }
    if (we == 1 && !w) {
      w = 1;
      vis[i] = 1;
      continue;
    }
    if (we == 6 && !e) {
      vis[i] = 1;
      e = 1;
      continue;
    }
    if (we == 8 && !r) {
      r = 1;
      vis[i] = 1;
      ;
      continue;
    }
    if (we == 9 && !t) {
      vis[i] = 1;
      t = 1;
      continue;
    } else
      mod = (mod * 10 + we) % 7;
  }
  mod = (mod * 10000) % 7;
  for (int i = 0; i < l; i++) {
    if (!vis[i]) {
      printf("%c", a[i]);
    }
  }
  if (mod == 0) {
    printf("1869");
  } else if (mod + 1 == 7) {
    printf("1968");
  } else if (mod + 2 == 7) {
    printf("1689");
  } else if (mod + 3 == 7) {
    printf("6198");
  } else if (mod + 4 == 7) {
    printf("1698");
  } else if (mod + 5 == 7) {
    printf("1986");
  } else if (mod + 6 == 7) {
    printf("1896");
  }
  while (p--) {
    printf("0");
  }
}
